Author davidsarah
Recipients David.Sankel, amaury.forgeotdarc, brian.curtin, christian.heimes, christoph, davidsarah, ezio.melotti, lemburg, mark, pitrou, ssbarnea, tim.golden, tzot, v+python, vstinner
Date 2011-01-10.22:15:04
SpamBayes Score 2.77059e-10
Marked as misclassified No
Message-id <>
> The script uses the console STD_OUTPUT_HANDLE iff sys.stdout.fileno()==1.

You may have missed "if not_a_console(hStdout): real_stdout = False".
not_a_console uses GetFileType and GetConsoleMode to check whether that handle is directed to something other than a console.

> But is it always the case?

The technique used here for detecting a console is almost the same as the code for IsConsoleRedirected at , or in WriteLineRight at (I got it from that blog, can't remember exactly which page).

[This code will give a false positive in the strange corner case that stdout/stderr is redirected to a console *input* handle. It might be better to use GetConsoleScreenBufferInfo instead of GetConsoleMode, as suggested by .]

> What about pythonw.exe?

I just tested that, using pythonw run from cmd.exe with stdout redirected to a file; it works as intended. It also works (for both console and non-console cases) when the handles are inherited from a parent process.

Incidentally, what's the earliest supported Windows version for Py3k? I see that mentions Windows ME. I can fairly easily make it fall back to never using WriteConsoleW on Windows ME, if that's necessary.
Date User Action Args
2011-01-10 22:15:09davidsarahsetrecipients: + davidsarah, lemburg, tzot, amaury.forgeotdarc, pitrou, vstinner, christian.heimes, tim.golden, mark, christoph, ezio.melotti, v+python, ssbarnea, brian.curtin, David.Sankel
2011-01-10 22:15:09davidsarahsetmessageid: <>
2011-01-10 22:15:04davidsarahlinkissue1602 messages
2011-01-10 22:15:04davidsarahcreate