buhtz
buhtz

Reputation: 12200

Should a warning go to stdout or stderr?

Should a warning message go to stdout or stderr?

Is this somewhere defined (e.g. in Posix)?

This question is doesn't related to a specific programming language or machine architecture.

Upvotes: 2

Views: 428

Answers (1)

Greg Hewgill
Greg Hewgill

Reputation: 994649

It depends. For example, suppose you're implementing a sort program. Your program reads its input from stdin and writes to stdout. Suppose you add an option to do a "numeric" sort instead of a lexicographic sort (the details aren't important). Suppose that you want to write a warning message if there aren't any numbers actually found in the input. Your sort will still work, but it might not be what the user intended. In that case, you would want to write your warning message to stderr, because stdout is reserved for the actual sorted data.

On the other hand, if you're writing a program to contact a web service API, read some JSON, extract some info, and write the info to a database, then perhaps writing a warning message to stdout is perfectly acceptable.

So, it depends on what your application is and how it uses stdout. There is no "standard".

Upvotes: 3

Related Questions