3 ms·
stderr is not for errors! (at least, not necessarily) It's for messaging things to the user. These are often errors, but there are some examples like curl that
by dickeytk 8y ago
stderr is not for errors! (at least, not necessarily) It's for messaging things to the user. These are often errors, but there are some examples like curl that use stderr for progress.
Leave it up to the CLI to decide what colors to use.
- lbotos 8y agowhy does curl used stderr over say stdout? (and happy to read any links you have, trying to learn)
- v_lisivka 8y agoStandard output for errors is for errors. If you need one more stream with your own rules, just open it. #include <stdio.h> int main(void) { /* Open third stream. Stream must be opened in shell using 3>... */ FILE *user = fdopen (3, "w"); /* If third stream is not open, then print to first stream. */ if (!user) user = fdopen(1, "w"); printf("Output.\n"); fprintf(stderr, "Error!\n"); fprintf(user, "Important message to user!\n"); fclose(user); return 0; } $ gcc test.c -o test $ ./test Output. Error! Important message to user! $ ./test 1>out.txt 2>error.log 3>/dev/tty Important message to user!
- dickeytk 8y agoWell first of all the docs say it's for "diagnostic output" http://pubs.opengroup.org/onlinepubs/9699919799/functions/stderr.html http://pubs.opengroup.org/onlinepubs/9699919799/functions/st... not "errors". Secondly, it doesn't matter what's right or not, the reality is CLIs (that you didn't write) generally use stderr for progress so you can't assume everything on it is an error.
- v_lisivka 8y agoGenerally, CLI turns out progress and colors when output is not connected to tty, so I can safely assume, in most cases. that everything on stderr is about errors. If not, I can always send my patch to upstream.
- v_lisivka 8y agoActually, Linux manual says: DESCRIPTION Under normal circumstances every UNIX program has three streams opened for it when it starts up, one for input, one for output, and one for printing diagnostic or error messages. These are typically attached to the user's terminal (see tty(4)) but might instead refer to files or other devices, depending on what the parent process chose to set up. (See also the "Redirection" section of sh(1).) The input stream is referred to as "standard input"; the output stream is referred to as "standard output"; and the error stream is referred to as "standard error". These terms are abbreviated to form the symbols used to refer to these files, namely stdin, stdout, and stderr.
- dickeytk 8y agoRight, as I said: stderr is not only for errors
- TeMPOraL 8y agoIn Common Lisp, you have following streams defined in the spec: *debug-io* - bidirectional, for interactive debugging *error-output* - output, for warnings and non-interactive error messages *query-io* - bidirectional, for asking user questions and reading answers *standard-input* - stdin *standard-output* - stdout *trace-output* - for tracing functions and timing execution You can redefine each of them independently. I think this granularity is much better than our usual stdin/stdout/stderr split we're used to. Note e.g. the query-io being separate from stdin/stdout, which means a properly defined way for a program to handle interactivity while simultaneously having data piped into stdin and out of stdout. It was IMO a good idea, and I wonder how the world ended up adopting just three standards streams in the end.