Friday, September 14th, 2007...10:13 am
Capturing STDERR with ruby backticks
Jump to Comments
I was writing a ruby script today that ran a linux command for every line in a file. The problem was the backtick operator in ruby only captures stdout, here's a little trick to get stderr as well. (*nix only)
out = `ourlinuxcmd 2>&1`
the 2>&1 bit tells the shell to redirect stderr to stdout







2 Comments
January 29th, 2009 at 4:47 pm
found this useful, thanks!
March 6th, 2010 at 9:11 am
This is actually just what I was looking for. This backticks thing opens up a whole world of Ruby scripting that I didn't know was possible.
Leave a Reply