From: ahoward Date: 2003-06-17T09:59:45+09:00 Subject: Re: popen, rsh, and File::NONBLOCK On Tue, 17 Jun 2003 nobu.nokada@softhome.net wrote: > 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 > 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 very cool - these will be in 1.8? > Note that IO#gets waits till a newline even in non-blocking mode. i did overlook that... > Only access mode has meanings in the second argument to IO.popen. NONBLOCK > is ignored here. i figured as much > # NOCTTY affects to only terminal device. if you are spawning an rsh command it is required though... > Basically, pipe(2) doesn't take optional flags. IO.popen just follows it. > It would be possible to treat the flag as special... i think it makes sense - but that's my opinion... of course there would be issues with fifos then where NONBLOCK *does* mean something... IMHO it would be very useful to be able to do something like stdin, stdout, stderr = Process.new 'external.sh' stdin.puts command puts stdout.gets # should not block puts stderr.gets # should not block essentially a means of sending commands to a process, getting back the stdout and stderr, and being able to do this without blocking on io. is this sufficiently common to put together an RCR? -a -- ==================================== | Ara Howard | NOAA Forecast Systems Laboratory | Information and Technology Services | Data Systems Group | R/FST 325 Broadway | Boulder, CO 80305-3328 | Email: ara.t.howard@noaa.gov | Phone: 303-497-7238 | Fax: 303-497-7259 | ~ > ruby -e 'p(%.\x2d\x29..intern)' ====================================