Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I determine if what a process is outputting is stdout or stderr?

share|improve this question
up vote 11 down vote accepted

There are only three ways I know of to determine what a program will output to STDOUT and what to STDERR

  1. Read the documentation. Or

  2. Experiment with redirection†

  3. print STDERR in red

†For example:

program > program.stdout 2> program.stderr

Then look at the two output files to see what the program has written to STDOUT and what it has written to STDERR.

Instead of redirection you can pipe to tee if you need output to continue to the screen as well as into a file. See

share|improve this answer
I usually use a variation of option 3: program | grep . prints STDOUT in red. – Dennis Jul 26 '12 at 1:49
Printing in red is pretty much exactly what I was looking for. Thanks RedGrittyBrick & Dennis – Rauffle Jul 26 '12 at 16:53

Based on your commented request:

{ { command; } 2>&3 | sed 's/^/STDOUT: /'; } 3>&1 1>&2 | sed 's/^/STDERR: /'
share|improve this answer
Looks impressive. But would you mind to add the cherries to your tree, and explain what it is doing? Not everybody around here is a guru -- and your construct is quite a little complex ;) – Izzy Jul 26 '12 at 11:49
The brackets are for ordering. I actually got that exact form from I-forget-where, but the point is to use extra file descriptors (beyond 1=stdout and 2=stderr) to take the output of the inner set of brackets, and run stdout through one sed command, while stderr goes through a different one. – zebediah49 Jul 26 '12 at 22:31
Wow. Didn't know to use those extra descriptors. First I was a bit confused (I like to understand what I run -- and got a bit confused with the curly braces). But now it's clear -- and IMHO exactly what the OP wanted. So +1 from me :) – Izzy Jul 27 '12 at 6:06
This helped me. I wanted to add more data into stderr. This does that and properly outputs everything back on stdout/stderr. { { { { echo "stdout" ; echo "stderr">&2; } 2>&3; } 3>&1 1>&2 | awk '{print "ERROR:",$0}' 1>&3; } 3>&2 2>&1; } – Bryan Drewery Mar 12 '13 at 12:49

If you want to do this once off, redirect one of them somewhere else.

Example, redirecting standard out with >.

ls -al > ls-l.txt (any output here is not from stdout, if you see anything it must be stderr output)

For stderr redirection use 2>

share|improve this answer
The process creates a constant stream of output, some to stdout some to stderr. I want to determine which is which as this output is going to the screen – Rauffle Jul 25 '12 at 22:47

You could just redirect stderr to a file and if anything shows up in it, it's from stderr.

e.g. ls -a 2> ls-all.txt

if there was an error for any reason sent to stderr, it will be redirected to this file.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .