I'd like help capturing a wxpython application output (currently printed to stdout) on Windows.
I've written a small wxpython GUI app that I run on Windows and Mac. A separate program (different language) calls this one. The caller uses the following syntax:
The python code (in $appPath) prints various things (with a simple print command to stdout) and these go into $output above, which the caller searches through.
On Mac this works without a problem. On Windows, I cannot seem to capture the python print statements. How do I capture stdout? I am currently compiling the python code with py2exe with "setup(windows=['register.py'])" I tried to change this from "windows" to "console" and it still does not work. In this case I see a console pop up (not surprisingly) but no output printed to it. Anyway, the console appearing is not desirable.
System: Windows XP, Python 2.5, wxPython 2.8.9.2, py2exe 0.6.9
I'd like help capturing a wxpython application output (currently printed to stdout) on Windows.
I've written a small wxpython GUI app that I run on Windows and Mac. A separate program (different language) calls this one. The caller uses the following syntax:
The python code (in $appPath) prints various things (with a simple print command to stdout) and these go into $output above, which the caller searches through.
On Mac this works without a problem. On Windows, I cannot seem to capture the python print statements. How do I capture stdout? I am currently compiling the python code with py2exe with "setup(windows=['register.py'])" I tried to change this from "windows" to "console" and it still does not work. In this case I see a console pop up (not surprisingly) but no output printed to it. Anyway, the console appearing is not desirable.
System: Windows XP, Python 2.5, wxPython 2.8.9.2, py2exe 0.6.9
Any suggestions will be greatly appreciated,
-k.
_____________
Where do you want the stdout to go? Into a file? In memory? Regardless, you need to create some kind of writeable object like a file handler and then set stdout to it, like so:
In there, you can re-direct stdout, but I can’t remember now how to get the real sys.stdout, as the default py2exe boot script re-directs it to nothing.
I think the problem is that on Windows the is no sys.stdout at the OS level. If I recall it is redirected to a ‘sink-hole’ someplace and isn’t accessible … but that’s just my fading memory. So when you tell py2exe that it is a window .exe, then it sets this up accordingly.
So I think Mike has you on the right track - create a writable object and redirect stdout to this.