Thursday, September 25, 2008

Pipe stderr to another process

In bash, suppose you want to save stdout to a file, but you want to pipe stderr to another process.
Here's how:

> myprocess 2>&1 > file.out | error_processor

This way of doing things in bash has always confused me, because it seems like you're putting stderr into stdout, then saving stdout in file.out. But it's backwards. Similarly, if you do

> myprocess > file.out 2>&1

you save both stderr and stdout to file.out. Counterintuitive!

No comments: