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 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.7705865e-10
Marked as misclassified No
Message-id <1294697709.54.0.22564631861.issue1602@psf.upfronthosting.co.za>
In-reply-to
Content
> The script unicode2.py 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 http://blogs.msdn.com/b/michkap/archive/2010/05/07/10008232.aspx , or in WriteLineRight at http://blogs.msdn.com/b/michkap/archive/2010/04/07/9989346.aspx (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 http://stackoverflow.com/questions/3648711/detect-nul-file-descriptor-isatty-is-bogus/3650507#3650507 .]

> 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 http://www.python.org/download/windows/ mentions Windows ME. I can fairly easily make it fall back to never using WriteConsoleW on Windows ME, if that's necessary.
History
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: <1294697709.54.0.22564631861.issue1602@psf.upfronthosting.co.za>
2011-01-10 22:15:04davidsarahlinkissue1602 messages
2011-01-10 22:15:04davidsarahcreate