StringIO class?

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 :slight_smile:

  require 'stringio'

  str = "hello world"
  io = StringIO.new(str)

Regards,

  Michael

···

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 ?

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 ?

require 'stringio'

somestring = ""
out = StringIO.new(somestring,"w")

$stderr = out

# Above is untested...

Hal

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

···

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 :slight_smile:

  require 'stringio'

  str = "hello world"
  io = StringIO.new(str)