You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
input() doesn't print the prompt if stderr is redirected #92715
If stderr is redirected, input() doesn't print the prompt. The same happens when stdout is redirected, but that is to be expected.
Code (in test.py):
x=input('prompt: ')
print(x)
When run:
> python test.py
prompt: text
text
> python test.py >out
text
> python test.py 2>err
text
text
The contents of out and err, respectively:
# out
prompt: text
# err
prompt:
The first and second cases are as expected. In the last case, the prompt is not printed, even though it should go into stdout, according to the documentation. Instead, it is printed to err.
changed the title [-]input() doesn't print anything if stderr is redirected[/-][+]input() doesn't print the prompt if stderr is redirected[/+]on May 12, 2022
I checked the first issue superficially, and I am not really sure it is a duplicate. Eryk's answer in the thread referenced in the penultimate comment, on the other hand, might explain what I have experienced (out is not a TTY, while the terminal is).
So in a sense this might be duplicate (of the thread at least), but the second last comment on that is from 6 years ago, so I don't know if that issue is considered being "alive".
@headst1337 Thank you; it's good to know that readline fixes the problem. However, I think the default behavior is wrong so this is more like a workaround. Also, I couldn't find any mention of this effect in the documentation either, so that should be updated as well, depending on how this ticket is resolved.
Activity
[-]input() doesn't print anything if stderr is redirected[/-][+]input() doesn't print the prompt if stderr is redirected[/+]sweeneyde commentedon May 12, 2022
This is probably a duplicate of:
Also related:
DavidNemeskey commentedon May 12, 2022
I checked the first issue superficially, and I am not really sure it is a duplicate. Eryk's answer in the thread referenced in the penultimate comment, on the other hand, might explain what I have experienced (
outis not a TTY, while the terminal is).So in a sense this might be duplicate (of the thread at least), but the second last comment on that is from 6 years ago, so I don't know if that issue is considered being "alive".
headst1337 commentedon Oct 15, 2024
To fix this you can
import readlineFor example:
and with fix:
DavidNemeskey commentedon Oct 16, 2024
@headst1337 Thank you; it's good to know that
readlinefixes the problem. However, I think the default behavior is wrong so this is more like a workaround. Also, I couldn't find any mention of this effect in the documentation either, so that should be updated as well, depending on how this ticket is resolved.