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.
There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.