36

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

Rauffle
  • 694
  • 2
  • 8
  • 13

4 Answers4

34

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 https://stackoverflow.com/q/692000/477035

12

Based on your commented request:

{ { command; } 2>&3 | sed 's/^/STDOUT: /'; } 3>&1 1>&2 | sed 's/^/STDERR: /'
1

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.

magna_nz
  • 121
-1

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>

Hennes
  • 65,804
  • 7
  • 115
  • 169