How do I redirect stdout and stderr separately in csh?

How do I redirect stdout and stderr separately in csh?

In csh, you can redirect stdout with ">", or stdout and stderr
together with ">&" but there is no direct way to redirect stderr
only. The best you can do is

( command >stdout_file ) >&stderr_file

which runs "command" in a subshell; stdout is redirected inside
the subshell to stdout_file, and both stdout and stderr from the
subshell are redirected to stderr_file, but by this point stdout
has already been redirected so only stderr actually winds up in
stderr_file.

If what you want is to avoid redirecting stdout at all, let sh
do it for you.

sh -c 'command 2>stderr_file'



Home FAQ