Redirecting STDERR
So you don’t like STDERR vomming all over your console?
This script almost works but doesn’t redirect anything that is already hold the original file descriptor, e.g. C extensions.
#!/usr/bin/env ruby
STDERR.puts "Something"
$stderr = File.open(File::NULL, 'w')
STDERR.puts "...and something else"
This however reopens the same file descriptor and covers all bases.
#!/usr/bin/env ruby
STDERR.puts "Something"
$stderr.reopen('/dev/null', 'w')
$stderr.sync = true
STDERR.puts "...and nothing"
And we get…
./test.rb
Something