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?
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"
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"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With