Sending stdout to multiple handles

D

Daniel Berger

Hi all,

How can I make it so that when I print to stdout, it actually prints to
both stdout and a file at the same time? Without redefining puts or
print or something similar, that is.

I'm trying to get the benchmark package to print to both stdout and a
file at the same time. I've been messing around with various IO
options, but I'm not hitting it, and io-tee seems to be dead.

Any ideas?

Regards,

Dan
 
N

nobu.nokada

Hi,

At Sun, 24 Jul 2005 13:05:58 +0900,
Daniel Berger wrote in [ruby-talk:149323]:
How can I make it so that when I print to stdout, it actually prints to
both stdout and a file at the same time? Without redefining puts or
print or something similar, that is.

Without redefining anything?

STDOUT.reopen("|tee output")
I'm trying to get the benchmark package to print to both stdout and a
file at the same time. I've been messing around with various IO
options, but I'm not hitting it, and io-tee seems to be dead.

I know nothing about io-tee, though what about this?

class IO
class Tee
attr_reader :ios
def initialize(*ios)
@ios = ios
end
def write
@ios.dup.each do |f|
f.write(str) rescue @ios.delete(f)
end
end
end
end

$stdout = IO::Tee.new(STDOUT)
class Object
remove_const:)STDOUT)
end
STDOUT = $stdout
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top