From: ara.t.howard@... Date: 2007-02-23T12:07:16+09:00 Subject: Re: IO.popen on Windows to filter stdout On Fri, 23 Feb 2007, Harold Hausman wrote: > > Hi Ara, thanks for taking the time to try and help me. What you're > saying about stderr here sounds right to me, but I tried what you have > above, and I'm still seeing the output I'm trying to 'squash' (read: > block) ... Here is my code: > ######################### > puts "ruby-link in the house!" > the_cmd = "old-Link.exe " > ARGV.each do |arg| > the_cmd << "\"#{arg}\" " > end > > the_cmd << "2>&1" > > puts "Calling: #{the_cmd}" > > IO.popen( the_cmd ) > ######################### > > And here is the output that I see: (apologies for badly wrapped lines) > ruby-link in the house! > Calling: old-Link.exe "@C:\long\path\to\some.rsp" "/NOLOGO" > "/ERRORREPORT:PROMPT" 2>&1 > OLD-LINK : > hrrrm. this is a windozing type thing, but is it perhaps manipulating the console directly? for instance, in unix, this can happen. 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 this should dump everything into a tempfile. if it does, then you should be able to manipulate the code with popen fine. > > ------ > So yeah, the output from old-Link.exe is still being filtered up to > the top and seen. What I'm looking for is a way to shut it up... ;) > >> alternatively, you may want to use systemu >> >> http://codeforpeople.com/lib/ruby/systemu >> > I looked at systemu and it's not clear how it would help with this > problem. :| Apologies if I'm being dense. harp:~ > cat a.rb require 'systemu' class Filter def initialize prefix, io @prefix = prefix @io = io end def << line @io << "#{ @prefix }: #{ line }" end end o = Filter.new 'stdout', STDOUT e = Filter.new 'stderr', STDERR systemu 'ruby -e"STDOUT.puts 42; STDERR.puts 42"', :stdout => o, :stderr => e harp:~ > ruby a.rb stdout: 42 stderr: 42 -a -- be kind whenever possible... it is always possible. - the dalai lama