how to get string printed by PyErr_Print( )?

Christian Heimes lists at cheimes.de
Wed Dec 19 04:55:31 EST 2007


grbgooglefan wrote:
> PythonC API function PyErr_Print( ) prints an error string onto stderr
> if PyErr_Occurred() is true.
> I don't want to print this to stderr because my Python+C code is
> running daemon mode & won't have terminal / stderr.
> So, I want to retrieve the string which PyErr_Print( ) will print.
> E.g., PyErr_Print() printed following string when I tried to call
> setTuple with one extra argument
> Traceback (most recent call last):
>   File "<string>", line 2, in isTacticSafe
> IndexError: tuple assignment index out of range

I suggest a different approach. A daemon must have a stdin, stdout and
stderr connected to a terminal. You can use freopen() to redirect stderr
and stdout to a log file and fclose() to close stdin.

http://www.gnu.org/software/libc/manual/html_mono/libc.html#Opening-Streams

Christian




More information about the Python-list mailing list