From: Tanner Burson Date: 2005-10-25T06:24:04+09:00 Subject: Re: $stderr.reopen bug? ------=_Part_47207_27739920.1130189041190 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 10/24/05, Eric Hodel wrote: > > > On Oct 24, 2005, at 1:16 PM, Tanner Burson wrote: > > > Hi, > > I'm working through what seems like it should be a simple operation, > > re-routing STDERR to point elsewhere. I can do the following > > > > $stderr.reopen("/dev/null") > > > > which works fine. But what I'd like to do is capture that output, so I > > figured StringIO would be the way to go. According to the docs for > > IO#reopen > > it can take an IO object as it's only parameter, and use that to re- > > open, > > but when I do the following > > > > require 'stringio' > > str_io =3D StringIO.new > > $stderr.reopen(str_io) > > > > I get > > > > TypeError: can't convert StringIO into String > > > > any ideas? > > $stderr =3D 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' =3D> false irb(main):008:0> str_io =3D StringIO.new("") =3D> # irb(main):009:0> $stderr =3D str_io =3D> # irb(main):010:0> `asdf` #bad command, dumps to stderr (irb):10: command not found: asdf =3D> "" irb(main):011:0> $stderr.rewind =3D> 0 irb(main):012:0> puts $stderr.read =3D> nil irb(main):013:0> as compared to the version reopening as file: irb(main):001:0> require 'stringio' =3D> true irb(main):002:0> $stderr.reopen('/dev/null','w+') =3D> # irb(main):003:0> `asdf` #bad command again =3D> "" any idea why there is such a difference between the two? -- > Eric Hodel - drbrain@segment7.net - http://segment7.net > FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 > > > > -- =3D=3D=3DTanner Burson=3D=3D=3D tanner.burson@gmail.com http://tannerburson.com <---Might even work one day... ------=_Part_47207_27739920.1130189041190--