Determine if output is stdout or stderr

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


Based on your commented request:

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

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.