capture stdout and stderror from within a Windows Service?
norseman at hughes.net
Thu May 14 13:02:21 EDT 2009
Chris Curvey wrote:
> I'm trying to get this invocation right, and it is escaping me. How
> can I capture the stdout and stderr if I launch a subprocess using
> subprocess.check_call()? The twist here is that the call is running
> from within a Windows service.
> I've tried:
> check_call("mycmd.exe", stdout=subprocess.PIPE) [raises an exception
> "An integer is required"]
mycmd.exe isn't open (running). the mycmd.exe is supposed to be a fn.
How did you start it?
> check_call("mycmd.exe", stdout=file("c:\\temp\\foobar.txt", "w"))
> [raises an exception "An integer is required"]
I think you need to run the .exe from your .py using the subprocess
module's commands and hook in at that time to stdin, stdout, ....
get the fn and use check_call() to see if .exe has something to say.
Check subprocess's help/man and so forth.
I know that if you start a program via os.Popen2's popen3 things work as
expected. How you would redirect I/O in an arbitrary already running
program in Windows is a good question.
More information about the Python-list