msvcrt.getch() returns EOF sentinel as data when no console is attached
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
"msvcrt.getch() returns EOF sentinel as data when no console is attached" --body "## Summary
On Windows, `msvcrt.getch()` returns the CRT EOF sentinel as normal Python data when no console is attached, instead of raising `OSError`.
Reproducer
```powershell
PCbuild\amd64\python_d.exe -c "import ctypes, msvcrt, sys; ctypes.windll.kernel32.FreeConsole(); sys.exit(0 if msvcrt.getch() == b'\xff' else 1)"
echo $LASTEXITCODE \``
Actual result:
`$LASTEXITCODE` is `0`
This means `msvcrt.getch()` returned `b'\xff'` after `FreeConsole()`.
Expected behavior
If `_getch()` fails because no console is attached, the Python wrapper should raise `OSError` instead of returning `b'\xff'`.
Environment
- OS: Windows 11
- Build: CPython debug build
- Command used to build: `PCbuild\build.bat -c Debug`"
CPython versions tested on:
3.15
Operating systems tested on:
Windows
Linked PRs
- gh-149450
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the msvcrt.getch() entry point and reproduce the behavior with the PCbuild/amd64/python_d.exe command after FreeConsole(). Confirm that a missing console no longer produces b'\xff' and instead raises OSError; the issue lists linked PR gh-149450, so check that work first.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100