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)

[ruby]
out = `ourlinuxcmd 2>&1`
[/ruby]

the 2>&1 bit tells the shell to redirect stderr to stdout

7 Comments

Leave a Reply