Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is STDERR redirected to STDOUT

Tags:

c

stdout

stderr

I noticed that we have mainly 3 file streams. They are STDIN, STDOUT and STDERR.. My question is why is STDERR redirected to STDOUT?

like image 663
user559208 Avatar asked Dec 31 '10 11:12

user559208


2 Answers

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
like image 69
Frédéric Hamidi Avatar answered Oct 05 '22 14:10

Frédéric Hamidi


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 image 25
Clifford Avatar answered Oct 05 '22 14:10

Clifford