Why is STDERR redirected to STDOUT
I noticed tha开发者_Go百科t we have mainly 3 file streams. They are STDIN, STDOUT and STDERR.. My question is why is STDERR redirected to STDOUT?
stderr
is not redirected to stdout
. Both streams are only connected to the same device (the current screen or terminal) by default.
You can redirect them to different files:
$ command > stdout.log 2> stderr.log
In order to actually redirect stderr
to stdout
, you have to issue:
$ command 2>&1
It is not; it just happens that both stdout and stderr are typically mapped to the same output stream (usually the console). If you redirect stdout to a file for example you will find that stderr remains directed to the console.
The important point is that they are independently redirectable.
Like stdout
, stderr
is usually directed to the output device of the standard console (generally, the screen). That means, stderr
is not redirected to stdout
but they share a common file descriptor. It is possible to redirect stderr
to some other destination from within a program using the freopen function.
精彩评论