From: ara.t.howard@... Date: 2007-02-23T23:54:54+09:00 Subject: Re: IO.popen on Windows to filter stdout On Fri, 23 Feb 2007, Harold Hausman wrote: > > I believe that the underlying executable that I'm dealing with, namely > VC8's "link.exe" is doing something very dastardly. > it sure looks like it! >> it's hard to say without seeing your code, and the old code, but you could >> try this to prove to yourself that stdout and stderr can be diverted: >> >> require 'tempfile' >> >> tmp = Tempfile.new Process.pid >> puts tmp.path >> >> cmd = "put the exact command here" >> >> STDOUT.reopen tmp.path >> STDERR.reopen tmp.path >> >> exec cmd >> > > When I integrate the above code, a tempfile is indeed created, but it > remains empty. And what's more? I *still* see the output in the > console! (: > > However, the following irb session indeed proves that stdout can be > redirected. (as well as makes me laugh out loud) > > irb(main):001:0> require 'tempfile' > => true > irb(main):002:0> tmp = Tempfile.new Process.pid > => # > irb(main):003:0> STDOUT.reopen tmp.path hmm. then it looks like what's happening might depend on the nature of stdin, i'd try one last thing require 'tempfile' i = Tempfile.new Process.pid o = Tempfile.new Process.pid e = Tempfile.new Process.pid puts i.path puts o.path puts e.path cmd = "put the exact command here" STDIN.reopen i.path STDOUT.reopen o.path STDERR.reopen e.path system cmd alternatively require 'systemu' class Filter def initialize prefix, io @prefix = prefix @io = io end def << line @io << "#{ @prefix }: #{ line }" end end i = '' o = Filter.new 'stdout', STDOUT e = Filter.new 'stderr', STDERR systemu 'ruby -e"STDOUT.puts 42; STDERR.puts 42"', :stdin=>i, :stdout=>o, :stderr=>e sorry i couldn't help more. cheers. -a -- be kind whenever possible... it is always possible. - the dalai lama