> $ cmd 2>&1 | another-cmd
>> will pipe both stdout and stderr to another-cmd (in bash, that is).
> There is bound to be a magic incantation to pipe stderr only.
for the benefit of newer linux users.
(kenn knows this stuff, but he must have been low on caffeine when he
replied :)
command 2> file-or-pipe
Mini shell redirection tutorial:
n> means redirect file descriptor n.
fd 1 is normally STDOUT, usually the terminal screen, so command > file
sends output to a file.
fd 2 is normally STDERR, where error messages are sent, usually the terminal
screen.
So to send the output of a command to "output-file", and the error messages
to "error-file", you do:
command > output-file 2> error-file
n>&m means: redirect file desc. n to the same place as file desc. m
Eg, 2>&1 means send STDERR to the same place as where we are sending STDOUT.
command > output 2>&1
means "redirect STDOUT to output, redirect STDERR to the same place as
STDOUT".
To redirect input, eg keyboard, you use < instead of >. Eg:
command < file1 2> output 1>&2
means: "run command, taking it's input from file, send STDERR to output, and
send STDIN to the same place"
etc.. etc...
-paul.
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!