embedded: redirecting stdout before you call Py_Initialize

Warren Postma embed at geocities.com
Thu Mar 2 12:14:34 EST 2000


[probably a FAQ, I searched the Python archives but couldn't find this exact
thing anywhere...]

How do you redirect stdout to your own place, such as a Win32 anonymous
pipe, before you even call Py_Initialize?  Is the key to redirect C's
stdout? How do you do that?

I already know once Python is initialized you can reassign it's stdout
object but that doesn't help me because by that point I've already missed
any errors or output written while Py_Initialize was trying to import
exceptions.py or site.py

I would prefer the output to go to a Win32 anonymous-pipe (CreatePipe gives
both a read HANDLE and a write HANDLE) and from the other side of the pipe,
I'll run a thread which I will write to some combination of a local console,
network socket, or to a file. Is there a code sample somewhere for this?

I suspect code modifications to Python would be required, because I already
have had to modify several key modules to get Python running on the RTOS
that I'm using, but so far I've only touched a handful of modules and only
in trivial ways.

Warren Postma

---

P.S. The following article [see deja link] is Close But No Cigar. I want to
hook python's stdout at an earlier time, before the interpreter itself is
initialized. The main point of my need is to catch and diagnose problems
like errors importing site.py or exceptions.py, etc. See link:
http://x40.deja.com/getdoc.xp?AN=447191861





More information about the Python-list mailing list