Ruby stdout and stderr

Very cool, thanks to a comment from a reader I just learned about the Ruby $stdout and $stderr variables. In short, you can write to STDOUT and STDERR in Ruby using code like this:

$stdout.puts "stdout"
$stderr.puts "stderr"

If you put those two lines in a Ruby script, and then run the script like this:

ruby test.rb > stdout 2> stderr

you'll find that the stdout and stderr files will contain the two different strings.

Ah, gotta love Ruby, a concise language that just does what you expect it to do.

 

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.