What should go to stdout/stderr and why Python logging write everything to stderr?

Grant Edwards grant.b.edwards at gmail.com
Tue Jan 3 17:51:29 EST 2023


On 2023-01-03, 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.

Programs that ask for passwords often do it by reading/writing to fd 0
or /dev/tty so that stdout is unaffected.

--
Grant



More information about the Python-list mailing list