StringIO class ?

L

Lothar Scholz

Hello, i must set the $stderr to an object that collects the data
inside a buffer. Is there something like pythons StringIO class ?
 
M

Michael Neumann

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)

Regards,

Michael
 
H

Hal Fulton

Lothar said:
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
 
S

Sean O'Dell

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::eek:pen("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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

StringIO 2
Need Help with Project 1
creating a StringIO object 1
StringIO and reopen 10
Uninitialized constant: String::StringIO 5
I want to redirect stderr to StringIO. 9
StringIO + unicode 1
StringIO 8

Members online

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,375
Latest member
FelishaCma

Latest Threads

Top