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
windows console: -i parameter and redirected output gives error in 3.13 #132962
Traceback (most recent call last):
File "D:\Sources\_pythonish\cpython\Lib\_pyrepl\main.py", line 59, in interactive_console
run_multiline_interactive_console(console)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
File "D:\Sources\_pythonish\cpython\Lib\_pyrepl\simple_interact.py", line 137, in run_multiline_interactive_console
statement = multiline_input(more_lines, ps1, ps2)
File "D:\Sources\_pythonish\cpython\Lib\_pyrepl\readline.py", line 396, in multiline_input
return reader.readline()
~~~~~~~~~~~~~~~^^
File "D:\Sources\_pythonish\cpython\Lib\_pyrepl\reader.py", line 744, in readline
self.prepare()
~~~~~~~~~~~~^^
File "D:\Sources\_pythonish\cpython\Lib\_pyrepl\historical_reader.py", line 306, in prepare
super().prepare()
~~~~~~~~~~~~~~~^^
File "D:\Sources\_pythonish\cpython\Lib\_pyrepl\reader.py", line 584, in prepare
self.console.prepare()
~~~~~~~~~~~~~~~~~~~~^^
File "D:\Sources\_pythonish\cpython\Lib\_pyrepl\windows_console.py", line 347, in prepare
self.height, self.width = self.getheightwidth()
~~~~~~~~~~~~~~~~~~~^^
File "D:\Sources\_pythonish\cpython\Lib\_pyrepl\windows_console.py", line 400, in getheightwidth
raise WinError(get_last_error())
OSError: [WinError 6] The handle is invalid.
And thus, we have a clue about OutHandle can't be used when redirect enabled.
If we add following check:
def getheightwidth(self) -> tuple[int, int]:
"""Return (height, width) where height and width are the height
and width of the terminal window in characters."""
info = CONSOLE_SCREEN_BUFFER_INFO()
if IsOutputRedirected:
return (1,1) # FIXME:
if not GetConsoleScreenBufferInfo(OutHandle, info):
raise WinError(get_last_error())
return (
info.srWindow.Bottom - info.srWindow.Top + 1,
info.srWindow.Right - info.srWindow.Left + 1,
)
we get removed original error, but if we try to input something we get another one (but very same):
Traceback (most recent call last):
File "D:\Sources\_pythonish\cpython\Lib\_pyrepl\main.py", line 59, in interactive_console
run_multiline_interactive_console(console)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
File "D:\Sources\_pythonish\cpython\Lib\_pyrepl\simple_interact.py", line 137, in run_multiline_interactive_console
statement = multiline_input(more_lines, ps1, ps2)
File "D:\Sources\_pythonish\cpython\Lib\_pyrepl\readline.py", line 396, in multiline_input
return reader.readline()
~~~~~~~~~~~~~~~^^
File "D:\Sources\_pythonish\cpython\Lib\_pyrepl\reader.py", line 750, in readline
self.handle1()
~~~~~~~~~~~~^^
File "D:\Sources\_pythonish\cpython\Lib\_pyrepl\reader.py", line 733, in handle1
self.do_cmd(cmd)
~~~~~~~~~~~^^^^^
File "D:\Sources\_pythonish\cpython\Lib\_pyrepl\reader.py", line 663, in do_cmd
self.refresh()
~~~~~~~~~~~~^^
File "D:\Sources\_pythonish\cpython\Lib\_pyrepl\reader.py", line 641, in refresh
self.console.refresh(self.screen, self.cxy)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Sources\_pythonish\cpython\Lib\_pyrepl\windows_console.py", line 193, in refresh
self._scroll(scroll_lines, self._getscrollbacksize())
~~~~~~~~~~~~~~~~~~~~~~~^^
File "D:\Sources\_pythonish\cpython\Lib\_pyrepl\windows_console.py", line 409, in _getscrollbacksize
raise WinError(GetLastError())
OSError: [WinError 0] The operation completed successfully.
And if we fix _getscrollbacksize and _scroll then we can exit from repl and get following text in t.t:
Running Release|x64 interpreter...
test
�[?2004h�[?25l�[1A
�[?25l�[?25l>>> �[?25h�[?25l�[?25l�[4D�[K\�[4D�[1B�[?25h�[1C�[1A�[?25l�[?25h�[?25l�[?25h�[?25l�[?25h�[?25l�[?25h�[?25l�[?25h�[?25l�[?25h�[1D
�[?2004l
Activity
johns1c commentedon Apr 25, 2025
A simple hello world program crashes if you mix the -i parameter with output redirection. I am using the Windows 11 WindowsTerminal.exe.
it did not happen using python 3.12 and can be prevented by setting the environment variable PYTHON_BASIC_REPL. e.g.
The failure gives the following output:-
StanFromIreland commentedon Apr 25, 2025
Unable to reproduce with main branch on linux.
The provided traceback is odd, 0 exit code?:
OSError: [WinError 0] The operation completed successfully.Also by the traceback this is a repl issue.
sergey-miryanov commentedon Apr 25, 2025
I can confirm it is reproduced on latest main on Windows.
Also, it is a bit interleaved with @chris-eibl PR https://github.com/python/cpython/pull/132884/files in the
GetLastErrorpart - if we useget_last_errorwe get following error:And thus, we have a clue about
OutHandlecan't be used when redirect enabled.If we add following check:
and following fix
we get removed original error, but if we try to input something we get another one (but very same):
And if we fix
_getscrollbacksizeand_scrollthen we can exit from repl and get following text int.t:chris-eibl commentedon Apr 25, 2025
The reason why we see
using
raise WinError(GetLastError()): #132888.pythongh-132962: _pyrepl: Prevent crash on Windows when stdout is red…
Merge branch 'main' into fix-pythongh-132962-win-repl-redirect
Merge branch 'python:main' into fix-pythongh-132962-win-repl-redirect
pythongh-132962: _pyrepl: Prevent crash on Windows when stdout is red…
Merge branch 'main' into fix-pythongh-132962-win-repl-redirect
Merge branch 'main' into fix-pythongh-132962-win-repl-redirect
vstinner commentedon Feb 3, 2026
This issue has been fixed by the change #144248.
Example:
StanFromIreland commentedon Feb 3, 2026
Closing as duplicate of the attached issue.
ctypes.GetLastError()in windows_console.py #132888