Thursday, March 14, 2013

Send STDERR to terminal output. STDOUT to file

How to send STDERR to the terminal output and the STDOUT to a file.

Normally the STDOUT and STDERR are both sent to the terminal output.

To split them up we can use ">" and "2>" for STDOUT and STDERR respectively.

generic example
( cool_prog > cool_file ) 2>&1

**note, the parentheses are required or else it will not work**

The Explanation:

cool_prog will attempt to send thing into STDOUT.  The ">" will send it into cool_file.
cool_prog will attempt to send thing into STDERR.  The "2>&1" will send it to terminal output.

">&" should achieve the same effect as "2>&1"

To find more look at these links

http://www.macobserver.com/tips/macosxcl101/2002/20020607.shtml

http://www.tldp.org/LDP/abs/html/io-redirection.html