This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients Segev Finer, eryksun, paul.moore, steve.dower, tim.golden, zach.ware
Date 2017-06-02.08:11:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The following is an example of the problem, right?

    >>> fd ='stdout.txt', os.O_CREAT | os.O_WRONLY)
    >>> os.dup2(fd, 1)
    >>> print('spam')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    OSError: [WinError 87] The parameter is incorrect

Code like this used to work, so possibly this needs to be addressed more generally. I have a couple ideas, but they're major changes. It's simpler to require code that pulls the rug out from under _WindowsConsoleIO to rebind sys.std*. 

For a counterexample, PyOS_StdioReadline always checks for a console and falls back on the old my_fgets function for a non-console. For example:

    >>> open('stdin.txt', 'w').write('x=42; os.dup2(oldfd, 0)\n')
    >>> fd ='stdin.txt', os.O_RDONLY)
    >>> oldfd = os.dup(0); os.dup2(fd, 0)
    >>> Breakpoint 0 hit
    00000000`66e98318 488bc4          mov     rax,rsp
    0:000> g
    >>> x
Date User Action Args
2017-06-02 08:11:17eryksunsetrecipients: + eryksun, paul.moore, tim.golden, zach.ware, steve.dower, Segev Finer
2017-06-02 08:11:17eryksunsetmessageid: <>
2017-06-02 08:11:17eryksunlinkissue30544 messages
2017-06-02 08:11:16eryksuncreate