Skip to content

Commit 36eb0f8

Browse files
committed
gh-132962: _pyrepl: Prevent crash on Windows when stdout is redirected
The interactive interpreter (-i) on Windows no longer crashes when standard output is redirected. The check for `CAN_USE_PYREPL` now also checks if stdout is a TTY on Windows, falling back to the basic REPL if it is not.
1 parent 49d7236 commit 36eb0f8

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

Lib/_pyrepl/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
raise RuntimeError("Windows 10 TH2 or later required")
1212
if not os.isatty(sys.stdin.fileno()):
1313
raise OSError(errno.ENOTTY, "tty required", "stdin")
14+
if sys.platform == "win32" and not os.isatty(sys.stdout.fileno()):
15+
raise OSError(errno.ENOTTY, "tty required", "stdout")
1416
from .simple_interact import check
1517
if err := check():
1618
raise RuntimeError(err)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The interactive interpreter (-i) on Windows no longer crashes when standard
2+
output is redirected. It now correctly falls back to the basic REPL in this
3+
situation.

0 commit comments

Comments
 (0)