GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — input() doesn't print the prompt if stderr is redirected · Issue #92715 · python/cpython

input() doesn't print the prompt if stderr is redirected #92715

New issue
Copy link
New issue
Copy link
Closed as duplicate
Closed as duplicate
input() doesn't print the prompt if stderr is redirected#92715
Copy link
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@DavidNemeskey
DavidNemeskey
opened on May 12, 2022
Issue body actions

Bug report

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.

Your environment

  • CPython versions tested on: 3.9.2
  • Operating system and architecture: Linux 5.11.0-40-generic [backport to 2.7] Change documentation's Show Source link to GitHub #44~20.04.2-Ubuntu SMP Tue Oct 26 18:07:44 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Activity

  1. DavidNemeskey
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on May 12, 2022
  2. DavidNemeskey
    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
  3. sweeneyde commented on May 12, 2022

    @sweeneyde
    sweeneyde
    on May 12, 2022
    Member
    More actions

    This is probably a duplicate of:

    • Change input() to always prompt to stderr #46221

    Also related:

    • Please add argument to override stdin/out/err in the input builtin #75784
  4. DavidNemeskey commented on May 12, 2022

    @DavidNemeskey
    DavidNemeskey
    on May 12, 2022
    Author
    More actions

    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".

  5. headst1337 commented on Oct 15, 2024

    @headst1337
    headst1337
    on Oct 15, 2024
    More actions

    To fix this you can import readline
    For example:

    ipanov@archlinux ~/u/sandbox > cat test_stderr.py
    
    input_msg = input('Enter text: ')
    print(input_msg)
    
    ipanov@archlinux ~/u/sandbox > python test_stderr.py 2>> out.txt
    123
    123
    ipanov@archlinux ~/u/sandbox >

    and with fix:

    ipanov@archlinux ~/u/sandbox > cat test_stderr.py
    
    import readline
    
    input_msg = input('Enter text: ')
    print(input_msg)
    
    ipanov@archlinux ~/u/sandbox > python test_stderr.py 2>> out.txt
    Enter text: 123
    123
    ipanov@archlinux ~/u/sandbox >
  6. DavidNemeskey commented on Oct 16, 2024

    @DavidNemeskey
    DavidNemeskey
    on Oct 16, 2024
    Author
    More actions

    @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.

    Reacted by Ivan Panov
  7. StanFromIreland
    closed this as a duplicateof Change input() to always prompt to stderr #46221 on May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.