Catching all that goes to $stderr

Hello,

how can I catch all output going to $stderr (e.g. to send some warning
emails time to time in case of daemon etc.)?

Thanks,

P.

On 7/28/06, Pavel S. [email protected] wrote:

Hello,

how can I catch all output going to $stderr (e.g. to send some warning
emails time to time in case of daemon etc.)?

Thanks,

P.

Something like this?

ioproxy = STDERR.dup

def ioproxy.write(*args, &block)
p args
#STDERR.write(*args, &block) # if you want to pass it on to real
STDERR
end

$stderr = ioproxy
puts “hello”
$stderr.puts “error!”
puts “world”
warn “oops!”

END
hello
[“error!”]
[“\n”]
world
[“oops!”]
[“\n”]

The newlines are because puts prints its args + newline. You could
easily filter that in the write method.

Regards,
Sean