tags:

views:

39

answers:

2

I am using the Python/C API with my app and am wondering how you can get console output with a gui app. When there is a script error, it is displayed via printf but this obviously has no effect with a gui app. I want to be able to obtain the output without creating a console. Can this be done?

Edit - Im using Windows, btw.

Edit - The Python/C library internally calls printf and does so before any script can be loaded and run. If there is an error I want to be able to get it.

+1  A: 

Use the logging package instead of printf. You can use something similar if you need to log output from a C function.

D.Shawley
You might take a look at http://logging.apache.org/log4cxx/index.html. I did not use it myself but this (and python logging) seem to be derived from log4j.
resi
A: 

If by printf you mean exactly thqt call from C code, you need to redirect (and un-buffer) your standard output (file descriptor 0) to somewhere you can pick up the data from -- far from trivial, esp. in Windows, although maybe doable. But why not just change that call in your C code to something more sensible? (Worst case, a geprintf function of your own devising that mimics printf to build a string then directs that string appropriately).

If you actually mean print statements in Python code, it's much easier -- just set sys.stdout to an object with a write method accepting a string, and you can have that method do whatever you want, including logging, writing on a GUI windows, whatever you wish. Ah were it that simple at the C level!-)

Alex Martelli