[issue37549] os.dup() fails for standard streams on Windows 7

Eryk Sun report at bugs.python.org
Thu Jul 11 07:02:44 EDT 2019


Eryk Sun <eryksun at gmail.com> added the comment:

> os.dup() doc says: "On Windows, when duplicating a standard stream 
> (0: stdin, 1: stdout, 2: stderr), the new file descriptor is 
> inheritable."

That's not necessarily correct. For example, if stdout is a pipe or disk file:

    C:\>python -V
    Python 3.7.3
    
    C:\>python -c "import os; fd = os.dup(1); print(os.get_inheritable(fd))" | more
    False

    C:\>python -c "import os; fd = os.dup(1); print(os.get_inheritable(fd))" > stdout.txt

    C:\>type stdout.txt
    False

What 3.7.3 does is to skip calling _Py_set_inheritable for all files of type FILE_TYPE_CHAR, which is wrong for character devices in general, such as NUL and serial ports. NUL is a common target for standard I/O redirection.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37549>
_______________________________________


More information about the Python-bugs-list mailing list