I think stdout, so you can easily grep, what do you think?
-
`stderr` of course. That is how everything in Unix expects it. – mirabilos Jan 03 '15 at 15:55
-
The possibly really correct [answer](https://unix.stackexchange.com/questions/8813/should-the-usage-message-go-to-stderr-or-stdout) ;-) – sphakka Jul 26 '18 at 17:06
5 Answers
Only errors go to stderr
. This is in no way an error, it does exactly what the user had in mind, which is print usage information.

- 25,711
- 35
- 110
- 162
-
Not "only errors"; **everything that is not output** goes to stderr. Logs go to stderr. Prompts go to stderr. Informational and diagnostic messages go to stderr. _But_ you are right: When a program is run with `--help`, the usage message is the intended output, so it belongs on stdout. – Charles Duffy Aug 29 '23 at 22:18
stdout
if the user requested it with --help
for example, makes it easier to pipe to less, grep it etc.
stderr
if you are showing the help text because there was a problem, e.g. parsing the command line arguments.

- 295,876
- 54
- 310
- 348
-
Well, (s)he specifically said "app --help" so I assume that "--help" is recognized as a command line argument. – Deniz Dogan Jul 01 '09 at 09:05
-
-
Not "might" use stderr but "should" use stderr in the non-`--help` case: If you're showing the help text because there was a usage problem, you don't want that usage message to be mixed up with your output (which might be going to a file or into a pipeline or to somewhere else the operator won't get a chance to see it). – Charles Duffy Aug 29 '23 at 22:20
-
Well, it's an explicit request for help so it's output. If for some reason you can't output the help or the user mis-spells "help" then, by all means, send that to error :-)
Users that know what they're doing can use the infamous "2>&1"
if they want errors on standard output.

- 854,327
- 234
- 1,573
- 1,953
It's not an error, so I'd say stdout....

- 316,276
- 54
- 369
- 333
-
**stderr is not only for errors** -- it's for absolutely everything intended to be read by a human operator rather than sent through whatever pipeline or file is receiving the program's intended output. (But then, when called with `--help`, a usage message _is_ the intended output; so this is right that stdout is the correct place, but faulty in the reasoning used to get there). – Charles Duffy Aug 29 '23 at 22:22
netcat is the only application I can think of that would redirect -h to stderr, and I can't for the life of me fathom why.
I suppose if you're outputting the help information because someone used improper arguments, you might want to redirect it to stderr, but personally even then I wouldn't use stderr because I don't think spamming error logs with fullblown help text is useful - I'd rather just output a single error pointing out the arguments were malformed to stderr. If someone is explicitly calling your application using -h or --help, then you really shouldn't redirect it to stderr.

- 1,692
- 1
- 14
- 10
-
stderr isn't just for error logs -- it's for _display to the human operator_, which is why (for example) shell prompts go to stderr rather than stdout. stdout goes into pipelines, so it'll often be parsed or consumed by a separate program. (The word of POSIX is that stderr is for "diagnostic" content, whereas stdout is only for output; knowing when a program is ready for more input, as indicated by a prompt, falls into the diagnostic category). – Charles Duffy Aug 29 '23 at 22:23