tags:

views:

291

answers:

2

I routed STDOUT to a file using this code:

STDOUT.reopen(File.open("./OUTPUT",'w+'))

Now I need to route STDOUT to the terminal again.

How would I do this?

+4  A: 

UPDATED

orig_std_out = STDOUT.clone
STDOUT.reopen(File.open('OUTPUT', 'w+'))
puts "test to file"
STDOUT.reopen(orig_std_out)
puts "test to screen"
khelll
A: 

You need to reopen STDOUT on file handle 1, which is the standard fd handle for stdout (0=stdin, 1=stdout, 2=stderr).

I'm not a Ruby guy, but I think this is about right:

STDOUT.reopen(IO.for_fd(1, "r"))
gavinb