user559208
user559208

Reputation: 1545

Why is STDERR redirected to STDOUT

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

Upvotes: 6

Views: 1473

Answers (3)

Frédéric Hamidi
Frédéric Hamidi

Reputation: 262939

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

Upvotes: 34

Clifford
Clifford

Reputation: 93476

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.

Upvotes: 5

Vijay Mathew
Vijay Mathew

Reputation: 27174

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.

Upvotes: 0

Related Questions