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 <1496391077.66.0.239111296724.issue30544@psf.upfronthosting.co.za>
In-reply-to
Content
The following is an example of the problem, right?

    >>> fd = os.open('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')
    24
    >>> fd = os.open('stdin.txt', os.O_RDONLY)
    >>> oldfd = os.dup(0); os.dup2(fd, 0)
    >>> Breakpoint 0 hit
    python36!my_fgets:
    00000000`66e98318 488bc4          mov     rax,rsp
    0:000> g
    >>> x
    42
History
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: <1496391077.66.0.239111296724.issue30544@psf.upfronthosting.co.za>
2017-06-02 08:11:17eryksunlinkissue30544 messages
2017-06-02 08:11:16eryksuncreate