What should go to stdout/stderr and why Python logging write everything to stderr?
Chris Angelico
rosuav at gmail.com
Tue Jan 3 17:40:59 EST 2023
On Wed, 4 Jan 2023 at 09:17, Michael Torrie <torriem at gmail.com> wrote:
>
> On 1/3/23 11:45, Keith Thompson wrote:
> > MRAB <python at mrabarnett.plus.com> writes:
> > [...]
> >> The purpose of stderr is to display status messages, logging and error
> >> messages, even user prompts, and not mess up the program's actual
> >> output. This is important on a *nix system where you might be piping
> >> the output of one program into the input of another.
> >
> > I would expect user prompts to be written to stdout, or perhaps to some
> > system-specific stream like the current tty, not to stderr. If a
> > program has user prompts, it probably doesn't make sense to pipe its
> > output to the input of another.
>
> I can't think of a specific example, but I know I have piped the output
> of a program while at the same time interacting with a prompt on stderr.
> A rare thing, though.
That can certainly happen, but you may more often see things that go
directly to the TTY rather than using the standard streams at all. For
example, ssh and sudo will prompt on the terminal if they need a
password, to avoid interfering with the standard streams (which can
and often will be redirected).
> Maybe some day an interface and shell syntax will be developed to
> interact with an arbitrary number of standard streams. Current piping
> syntax really only works well with one stream and even trying to use
> stderr and stdout with pipes and filters in a shell is awkward.
Yeah, maybe some day. And then maybe someone will use a time machine
to backport it into bash. You have at least ten available, with more
being possible but potentially causing conflicts:
https://www.gnu.org/software/bash/manual/html_node/Redirections.html
ChrisA
More information about the Python-list
mailing list