Standard Streams - Standard Error (stderr)

Standard Error (stderr)

Standard error is another output stream typically used by programs to output error messages or diagnostics. It is a stream independent of standard output and can be redirected separately. The usual destination is the text terminal which started the program to provide the best chance of being seen even if standard output is redirected (so not readily observed). For example, output of a program in a pipeline is redirected to input of the next program, but errors from each program still go directly to the text terminal.

It is acceptable—and normal—for standard output and standard error to be directed to the same destination, such as the text terminal. Messages appear in the same order as the program writes them, unless buffering is involved. (For example, a common situation is when the standard error stream is unbuffered but the standard output stream is line-buffered; in this case, text written to standard error later may appear on the terminal earlier, if the standard output stream's buffer is not yet full.)

The file descriptor for standard error is 2; the POSIX definition is STDERR_FILENO; the corresponding variable is FILE* stderr. The C++ standard header provides two variables associated with this stream: std::cerr and std::clog, the former being unbuffered and the latter using the same buffering mechanism as all other C++ streams.

Most shells allow both standard output and standard error to be redirected to the same file using

&> filename

Bourne-style shells allow standard error to be redirected to the same destination that standard output is directed to using

2>&1

csh-style shells allow standard error to be redirected to the same destination that standard output is directed to using

>&

Read more about this topic:  Standard Streams

Famous quotes containing the words standard and/or error:

    This unlettered man’s speaking and writing are standard English. Some words and phrases deemed vulgarisms and Americanisms before, he has made standard American; such as “It will pay.” It suggests that the one great rule of composition—and if I were a professor of rhetoric I should insist on this—is, to speak the truth. This first, this second, this third; pebbles in your mouth or not. This demands earnestness and manhood chiefly.
    Henry David Thoreau (1817–1862)

    Never miss an opportunity to allow a child to do something she can and wants to on her own. Sometimes we’re in too much of a rush—and she might spill something, or do it wrong. But whenever possible she needs to learn, error by error, lesson by lesson, to do better. And the more she is able to learn by herself the more she gets the message that she’s a kid who can.
    Polly Berrien Berends (20th century)