Eryk Sun added the comment: 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 ---------- keywords: +3.2regression nosy: +eryksun _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue30544> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com