From: Daniel Berger Date: 2005-10-25T05:29:02+09:00 Subject: Re: $stderr.reopen bug? 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 = StringIO.new > $stderr.reopen(str_io) > > I get > > TypeError: can't convert StringIO into String > > any ideas? Is the documentation just wrong, and it can only take a string > arg? Or will it take only a File IO object? You'll need an IO object because, behind the scenes, IO.reopen grabs the fileno from the object and uses the dup2() function (at least, on *nix). The StringIO#fileno method exists, but returns nil, since there is no associated fileno with a StringIO object. Actually, I don't even think it gets that far. I suspect it's choking on the rb_io_get_io() internal function. Whether or not this could be made to work with StringIO, I'm not sure. Regards, Dan