From: Sean O'Dell Date: 2004-06-21T03:55:36+09:00 Subject: Re: StringIO class ? On Sunday 20 June 2004 06:51, Michael Neumann wrote: > On Sun, Jun 20, 2004 at 10:33:16PM +0900, Lothar Scholz wrote: > > Hello, i must set the $stderr to an object that collects the data > > inside a buffer. Is there something like pythons StringIO class ? > > Have you tried StingIO :-) > > require 'stringio' > > str = "hello world" > io = StringIO.new(str) That works for the most part. If you ever have trouble getting EVERYTHING captured that's going to $stderr, just pipe all fd[2] output to a file: # redirect stderr $new_stderr = File::open("capture_file"); $old_stderr = $stderr.clone $stderr.reopen($new_stderr); # ... STDERR is captured here ... # restore stderr $stderr.reopen($old_stderr); $new_stderr.close Now you have a file named "capture_file" which has everything that was sent to stderr, even from code that didn't use Ruby's $stderr object. Sean O'Dell