The DOS shell,
command.com, offers no mean to redirect stderr.
Because of that, it's impossible to save to a file, or pipe into a program,
the messages that a program prints to stderr. "
foo >out" only
redirects stdout of
foo, not stderr. The latter still goes to the
Since stderr is typically where important error messages are printed, this is extremely unfortunate, as this makes us unable to detect errors in unattended jobs.
So what do you do ? One solution is to switch to Unix, where the shell
allows one to redirect stderr. With
sh and its derivatives, use
to save both stdout and stderr of
foo >out 2>&1
out. Similarly, use
to pipe both stdout and stderr of
foo 2>&1 | bar
bar. If you're stuck with DOS, Stderr is what you need.
Stderr runs a command and merges its stderr into its stdout. Therefore, redirecting or piping stdout is equivalent to doing the same thing to stderr as well.
To redirect stdout and stderr of
foo *.txt to
stderr foo *.txt >out
To pipe stdout and stderr of
foo *.txt into
stderr foo *.txt | bar
Rule of thumb : type the command as you would normally do, but
prepended by "
Stderr can run any type of command, be it an executable or a batch file,
with any number of arguments. Since the command is run through the shell, the
COMSPEC must be set (it always is). Since
the command is a child process of Stderr, Stderr (and the resident part of the
shell) remain in memory during the execution of the command. This means that
there is less memory available to the command than if it was run directly
through the top-level shell. In the case of
about 11 kB less.
Stderr is a good example application of the frequently misunderstood
dup2 system call.
Microsoft C 5.1 included a program named
errout. Stderr and
errout are not equivalent.
errout can redirect
stdout and stderr to different files; Stderr cannot. Stderr can pipe stderr
into another program;
more command-line real estate (at minimum 4 more characters) and more memory
.COM. A C version would also be useful, for different reasons (educational purposes).