From: nobu.nokada@... Date: 2003-06-17T09:05:40+09:00 Subject: Re: popen, rsh, and File::NONBLOCK Hi, At Tue, 17 Jun 2003 06:17:25 +0900, ahoward wrote: > this a bit of *nix question, but, using pipes, how does one either > > a) determine if an IO.gets/read etc would block io/wait in rough provides IO#ready?. $ ruby -rio/wait -e 'cat = IO.popen "cat", "r+";cat.puts "foobar";sleep 0.1;p cat.ready?;p cat.gets;p cat.ready?' 7 "foobar\n" nil > or > > b) use non-blocking io with pipes Also nonblock.rb is in io/wait. $ ruby -rio/nonblock -e 'cat = IO.popen "cat", "r+";cat.nonblock=true;cat.puts "foobar";p cat.gets;p cat.read(1)' "foobar\n" -e:1:in `read': Resource temporarily unavailable (Errno::EAGAIN) from -e:1 Note that IO#gets waits till a newline even in non-blocking mode. > this certainly does not work... > > ~/eg/ruby > irb > irb(main):001:0> cat = IO.popen 'cat', File::RDWR | File::NOCTTY | File::NONBLOCK Only access mode has meanings in the second argument to IO.popen. NONBLOCK is ignored here. # NOCTTY affects to only terminal device. > does popen then not respect the File::NONBLOCK? perhaps this is a limitation > of pipes themselves then... Basically, pipe(2) doesn't take optional flags. IO.popen just follows it. It would be possible to treat the flag as special... -- Nobu Nakada