Capturing stdout on windows

Hi List,

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:

LAUNCH EXTERNAL PROCESS($appPath;$input;$output;$error)

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.

Ken Mankoff wrote:

Hi List,

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:

LAUNCH EXTERNAL PROCESS($appPath;$input;$output;$error)

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:

<code>

import sys
sys.stdout = someWriteableObj

</code>

I have an example for redirecting text to a text control (wxPython - Redirecting stdout / stderr - Mouse Vs Python), but I doubt you want that. You could also use Python's logging module.

···

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

__________ Information from ESET NOD32 Antivirus, version of virus signature database 3988 (20090404) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

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.

g.