Message125938
> 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. |
|
Date |
User |
Action |
Args |
2011-01-10 22:15:09 | davidsarah | set | recipients:
+ 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:09 | davidsarah | set | messageid: <1294697709.54.0.22564631861.issue1602@psf.upfronthosting.co.za> |
2011-01-10 22:15:04 | davidsarah | link | issue1602 messages |
2011-01-10 22:15:04 | davidsarah | create | |
|