[issue10080] Py_Initialize crashes when stdout has been redirected with freopen

Antoine Pitrou report at bugs.python.org
Wed Oct 13 18:52:24 CEST 2010


Antoine Pitrou <pitrou at free.fr> added the comment:

> Also, dup2 is not available on Windows (at least not from what I've
> read).

MSDN says dup2 is deprecated but you can use _dup2 instead:
http://msdn.microsoft.com/en-us/library/8syseb29%28v=VS.80%29.aspx

> From my understanding, freopen() is supposed to be the portable way to
> redirect stdout.

I'm not sure, but as I said Python does not use C's "stdout". Instead,
it writes directly (using write()) to the file descriptor number 1. So,
if freopen() creates a different file descriptor for the C stdout,
Python's stdout will not be redirected where you want it to be.

I'm not saying that's what happens in your program, though. You could
call _fileno(stdout) after the reopen() call to check if it's still 1 or
not.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10080>
_______________________________________


More information about the Python-bugs-list mailing list