Catching all that goes to $stderr

Discussion in 'Ruby' started by Pavel Smerk, Jul 28, 2006.

  1. Pavel Smerk

    Pavel Smerk Guest

    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.
    Pavel Smerk, Jul 28, 2006
    #1
    1. Advertising

  2. On 7/28/06, Pavel Smerk <> 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
    Sean O'Halpin, Jul 28, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QWRyaWphbiBKb3NpYw==?=

    catching all requests with a single page

    =?Utf-8?B?QWRyaWphbiBKb3NpYw==?=, Feb 6, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    389
    bruce barker
    Feb 6, 2004
  2. Rutger Claes
    Replies:
    1
    Views:
    6,625
    spaghetti
    Jul 7, 2003
  3. Fred
    Replies:
    2
    Views:
    388
    Eric Bohlman
    Dec 14, 2003
  4. Bryan Olson
    Replies:
    9
    Views:
    349
    Bryan Olson
    Aug 13, 2005
  5. Replies:
    37
    Views:
    2,053
    Flash Gordon
    Jan 9, 2006
Loading...

Share This Page