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


Leave a Reply