Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I output warnings to STDERR or STDOUT?

I'm making a script that handles a predefined set of data, outputting to a file. I want to pop up a warning when one datum (which is always "Regular" in every set that I've had access to) is different stating that this value is unhandled (since I don't know how it affects the data). Should I output this warning to stderr or stdout?

like image 389
Stuart P. Bentley Avatar asked Sep 16 '09 04:09

Stuart P. Bentley


People also ask

Should warnings go to stderr or stdout?

Warning logs are not errors. None of these should go to stderr by default. Only error logs should go to stderr.

What is the difference between stdout and stderr explain your answer?

Your screen is the standard output, sometimes denoted as stdout . By default, commands take input from the standard input and send the results to standard output. Standard error, sometimes denoted as stderr, is where error messages go. By default, this is your screen.

Can you read from stderr?

STDERR_FILENO is an output file descriptor. You can't read from it.


1 Answers

If I saved the output of this script (i.e. stdout only) so that I could process it later, would that warning interfere with how the output is parsed? Moreover, if output is piped to another process, the warning should show up on the terminal, so the user sees it immediately.

For those reasons, in general, you output warnings to stderr.

like image 99
Mark Rushakoff Avatar answered Sep 20 '22 01:09

Mark Rushakoff