On Oct 24, 2005, at 2:24 PM, Tanner Burson wrote: > On 10/24/05, Eric Hodel <drbrain / segment7.net> wrote: > >> $stderr = str_io >> >> $stderr.puts 'hi' >> warn 'warning' >> >> $stderr.rewind >> puts $stderr.read > > I tried this approach first, and it didn't seem to accomplish > anything (IRB > dump below) > > irb(main):007:0> require 'stringio' > => false > irb(main):008:0> str_io = StringIO.new("") > => #<StringIO:0x402f8df8> > irb(main):009:0> $stderr = str_io > => #<StringIO:0x402f8df8> > irb(main):010:0> `asdf` #bad command, dumps to stderr > (irb):10: command not found: asdf > => "" > irb(main):011:0> $stderr.rewind > => 0 > irb(main):012:0> puts $stderr.read > > => nil > irb(main):013:0> > > as compared to the version reopening as file: > > irb(main):001:0> require 'stringio' > => true > irb(main):002:0> $stderr.reopen('/dev/null','w+') > => #<IO:/dev/null> > irb(main):003:0> `asdf` #bad command again > => "" > > any idea why there is such a difference between the two? You really want open3: require 'open3' stdin, stdout, stderr = Open3.popen3('your command') -- Eric Hodel - drbrain / segment7.net - http://segment7.net FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04