Determine if output is stdout or stderr
Solution 1
There are only three ways I know of to determine what a program will output to STDOUT and what to STDERR
Read the documentation. Or
Experiment with redirection†
†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
Solution 2
Based on your commented request:
{ { command; } 2>&3 | sed 's/^/STDOUT: /'; } 3>&1 1>&2 | sed 's/^/STDERR: /'
Solution 3
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.
Related videos on Youtube
Sunil
Updated on September 18, 2022Comments
-
Sunil over 1 year
I'm using Telerik winform controls with VS2015. I add controls manually in toolbox. I can work as far as VS is running. When I close VS then they disappear. Next time to work with them I need to add again. I've faced same problem before with infragistics controls. Is there any solution that keeps controls sticking in toolbox all the time?
-
halfer almost 7 yearsPlease read Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers? - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions.
-
-
Rauffle almost 12 yearsThe 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
-
Dennis almost 12 yearsI usually use a variation of option 3:
program | grep .
prints STDOUT in red. -
Izzy almost 12 yearsLooks 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 ;)
-
zebediah49 almost 12 yearsThe 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 runstdout
through onesed
command, whilestderr
goes through a different one. -
Izzy almost 12 yearsWow. 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 :)
-
Bryan Drewery about 11 yearsThis 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; }