From: Tom Pollard Date: 2006-11-01T11:37:29+09:00 Subject: Re: Nonblocking IO read On Oct 31, 2006, at 7:20 PM, srobertjames@gmail.com wrote: > In the interests of promoting creativity, I'll ask the question > without > any prior assumptions: > > I'm using popen4 (great gem, btw) to run an external command and > capture stdout and stderr. If one (or both) of those is empty, I > don't > want to hang. Just keep on moving. In fact, stderr will normally be > empty. > > How could I do this? Have you tried simply reading from them? When the command terminates, that should close those pipes on the command's end. At that point, a simple read on the stdout handle, for instance, will return whatever output there was and then eof. If there's no output, the read should return immediately. Did you try that yet? Did you try the (Windows-oriented) example from the 'ri Open4' page? If you're working in Unix you could try status = POpen4::poen4('cat -') do |stdout, stderr, stdin| stdin.puts 'hello world' stdin.close puts "stdout: #{stdout.read.strip}" puts "stderr: #{stderr.read.strip}" end Anyway, you would only need nonblocking IO if you wanted to read bits of the stderr stream before the command exited, but that doesn't sound like what you're want. Tom