when embedding Python, how do you redirect stdout/stderr?

David Gravereaux davygrvy at pobox.com
Thu Jun 14 10:48:50 EDT 2001


Hi all,

The subject says it all.  I'm embedding (or trying) and want to have all std
traffic sent to a custom textbox in a windows GUI.  Is there anyway to do this?
A good place for examples for me to read?  I played around a little bit with
this, but need a more stream'ish way:

        output = PycStringIO->NewOutput(1024);

	/* capture all interpreter error output */
        PySys_SetObject("stderr", output);

	/* so that error is printed on standard error, redirected above */
        PyErr_Print();
        message = PycStringIO->cgetvalue(output);
        string = PyString_AsString(message);
        length = PyString_Size(message);

I've since updated the exception getting part, so I don't have to redirect, but
I do need to have the std traffic now go somewhere.  Any ideas?
--
David Gravereaux <davygrvy at pobox.com>
-=[ Ray's Famous and Truly the Original Pizza, NYC ]=-



More information about the Python-list mailing list