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 Mitchell.Stokes
Recipients Mitchell.Stokes
Date 2010-10-13.04:11:13
SpamBayes Score 7.2081263e-10
Marked as misclassified No
Message-id <1286943075.1.0.984332542932.issue10080@psf.upfronthosting.co.za>
In-reply-to
Content
I have Python embedded in a C/C++ program, and I'm trying to redirect stdout to a text file. Since I'm trying to get rid of the console, I want C and Python stdout going to the text file (so, not sys.stdout = open('log.txt', 'w')). To this end, I used freopen() like so:

freopen("log.txt", "w", stdout);

to redirect stdout in C. However, when using Python 3.1, I get the following error:

Fatal Python error: Py_Initialize: can't initialize sys standard streams
OSError: [Errno 9] Bad file descriptor

followed by a crash (Runtime Error). I think this is somewhat related to this bug: http://bugs.python.org/issue1415

I've attached a sample program that illustrates the problem. I compiled it with:

gcc -o py_main.exe py_main.c -IC:\Python31\include -LC:\Python31\libs -lpython31

I had someone test the sample program on Linux, and it worked fine there, so I think it's a Windows issue.
History
Date User Action Args
2010-10-13 04:11:15Mitchell.Stokessetrecipients: + Mitchell.Stokes
2010-10-13 04:11:15Mitchell.Stokessetmessageid: <1286943075.1.0.984332542932.issue10080@psf.upfronthosting.co.za>
2010-10-13 04:11:13Mitchell.Stokeslinkissue10080 messages
2010-10-13 04:11:13Mitchell.Stokescreate