Tuesday, October 2, 2012

redirect STDIN, STDOUT and STDERROR

You can redirect STDIN, STDOUT and STDERRORs when running applications from the shell (or command prompt).

To redirect STDIN, use "<". The command looks like:
$ some-command < /path/to/some/file

To redirect STDOUT, use ">". The command looks like:
$ some-program > /path/to/some/file

To append STDOUT redirect output use ">>".The command looks like:
$ some-program >> /path/to/some/file

To redirect STDERR, you need to know about File Descriptors (FD). Check the reference for additional details. You need to use "n>&m" operator. It means to redirect FD n to the same places as FD m. Eg, 2>&1 means send STDERR to the same place that STDOUT is going to. The command looks like
$ some-program >> /path/to/some/file 2>&1

Reference:
1. http://www.linuxsa.org.au/tips/io-redirection.html

No comments:

Post a Comment