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] os.device_encoding(fd) should support any console fd #87587
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2021-03-06.15:04:20.125>labels= ['3.8', '3.9', 'extension-modules', 'interpreter-core', 'type-bug', 'expert-IO', '3.10', 'OS-windows']
title='os.device_encoding(fd) should support any console fd in Windows'updated_at=<Date2021-03-06.15:04:20.125>user='https://github.com/eryksun'
In Windows, os.device_encoding() is hard coded to map file descriptor 0 and descriptors 1 and 2 respectively to the console's input and output code page if isatty(fd) is true. But isatty() is true for any character device, such as "NUL". Also any fd might be a console, by way of dup(), dup2() -- or open() with the device names "CON", "CONIN$", and "CONOUT$".
The correct device encoding of a console file is needed for use with os.read() and os.write(). It's also necessary for io.TextIOWrapper() if PYTHONLEGACYWINDOWSSTDIO is set.
_Py_device_encoding() in Python/fileutils.c should use _get_osfhandle() to get the OS handle, and, if it's a character-device file, determine the code page to return, if any, depending on whether it's an input or output console file. For example:
changed the title [-]os.device_encoding(fd) should support any console fd in Windows[/-][+][Windows] os.device_encoding(fd) should support any console fd[/+]on Aug 8, 2022
Activity
eryksun commentedon Mar 6, 2021
In Windows, os.device_encoding() is hard coded to map file descriptor 0 and descriptors 1 and 2 respectively to the console's input and output code page if isatty(fd) is true. But isatty() is true for any character device, such as "NUL". Also any fd might be a console, by way of dup(), dup2() -- or open() with the device names "CON", "CONIN$", and "CONOUT$".
The correct device encoding of a console file is needed for use with os.read() and os.write(). It's also necessary for io.TextIOWrapper() if PYTHONLEGACYWINDOWSSTDIO is set.
_Py_device_encoding() in Python/fileutils.c should use _get_osfhandle() to get the OS handle, and, if it's a character-device file, determine the code page to return, if any, depending on whether it's an input or output console file. For example:
[-]os.device_encoding(fd) should support any console fd in Windows[/-][+][Windows] os.device_encoding(fd) should support any console fd[/+]gh-87587: Fix os.device_encoding() for any console on Windows (GH-155410
[3.13] gh-87587: Fix os.device_encoding() for any console on Windows (G…
[3.14] gh-87587: Fix os.device_encoding() for any console on Windows (G…
pythongh-87587: Fix os.device_encoding() for any console on Windows (p…
[3.15] gh-87587: Fix os.device_encoding() for any console on Windows (G…