David-Sarah Hopwood <david-sa...@jacaranda.org> added the comment:

"... os.dup2() ..."

Good point, thanks.

It would work to change os.dup2 so that if its second argument is 0, 1, or 2, 
it calls _get_osfhandle to get the Windows handle for that fd, and then reruns 
the console-detection logic. That would even allow Unicode output to work after 
redirection to a different console.

Programs that directly called the CRT dup2 or SetStdHandle would bypass this. 
Can we consider such programs to be broken? Methinks a documentation patch for 
os.dup2 would be sufficient, something like:

"When fd1 refers to the standard input, output, or error handles (0, 1 and 2 
respectively), this function also ensures that state associated with Python's 
initial sys.{stdin,stdout,stderr} streams is correctly updated if needed. It 
should therefore be used in preference to calling the C library's dup2, or 
similar APIs such as SetStdHandle on Windows."

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue1602>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to