Search code examples
rubystdoutstderr

How to turn off $stdout and $stderr in Ruby


Is it possible to turn off $stdout and $stderr and not re-direct it to a file; just turn it off so it prints out nothing to anywhere?

I've already tried the following code, but it just errors with error: Invalid argument

$stderr = IO.new(0,"w")
$stdout = IO.new(0,"w")

Solution

  • This gist will show you how to redirect to /dev/null:

    https://gist.github.com/moertel/11091573

    Or this SO answer:

    How do I redirect stderr and stdout to file for a Ruby script?

    Your question probably needs to be marked as a dup.