A vertical bar character (
) on a command line
pipes the standard output of a process to another process.
How can you pipe the standard error, not the standard output?
You might want to put a long-running
command in the background,
save the output to a file, and mail yourself a copy of the errors.
In the C shell, run the command in a
The standard output of the command is redirected inside the subshell.
All that's left outside the subshell is the
standard error; the
redirects it (along with the empty standard output) to the
) |& mail
Of course, you don't need to put that job
in the background (
If you want the standard output to go to your terminal instead of a text
The Bourne shell gives you a lot more flexibility and lets you do
just what you need.
The disadvantage is the
more complicated syntax (
Here's how to run your
program, route the
through a pipe to the
program, and leave
going to your
(cruncher 3>&1 1>&2 2>&3 3>&-) | mail
to an output file and send
down a pipe,
(cruncher 3>&1 >
2>&3 3>&-) | mail