From: Bruce Williams Date: 2003-03-27T07:47:15+09:00 Subject: Re: tee in ruby while catching status On Wednesday 26 March 2003 05:22 pm, Daniel Bretoi wrote: | I take it back, I didn't. | This is what I have now: | | require 'open3' | def doit(command) | logfile = command.shift | Open3.popen3(command.join(' ')) { |inp,out,err| | fh = File.open(logfile,"w") | out.each { |line| puts line; fh.print line } | err.each { |line| puts line; fh.print line } | } | $? >> 8 | end | | however, as you can see, all the stderr stuff will be always shown at | the end. Is there no way to mix stdout and stderr the way it would | naturally be displaye don the screen at runtime? | | db | I think using IO::select / Kernel::select may help: --------------------------------------------------------- Kernel::select select( readArray [, writeArray [errorArray [timeout]]] ) -> anArray or nil ------------------------------------------------------------------------ Performs a low-level select call, which waits for data to become available from input/output devices. The first three parameters are arrays of IO objects or nil. The last is a timeout in seconds, which should be an Integer or a Float. The call waits for data to become available for any of the IO objects in readArray, for buffers to have cleared sufficiently to enable writing to any of the devices in writeArray, or for an error to occur on the devices in errorArray. If one or more of these conditions are met, the call returns a three-element array containing arrays of the IO objects that were ready. Otherwise, if there is no change in status for timeout seconds, the call returns nil. If all parameters are nil, the current thread sleeps forever. select( [$stdin], nil, nil, 1.5 ) #=> [[#], [], []] AFAIK using this you can 'multiplex' data from several IO objects in order. Hope this helps! -- author: Bruce R. Williams url: http://codedbliss.com irc: { nick: iusris, channel: ruby-lang, server: irc.freenode.net } quote: > It does not require a majority to prevail, but rather an irate, tireless minority keen to set brush fires in people's minds.' -- Samuel Adams