capture stdout and stderror from within a Windows Service?

Grant Edwards invalid at invalid
Thu May 14 18:16:51 CEST 2009


On 2009-05-14, Chris Curvey <ccurvey at gmail.com> 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"]
>
> check_call("mycmd.exe", stdout=file("c:\\temp\\foobar.txt", "w"))
> [raises an exception "An integer is required"]

An educated guess...

By default, subprocess will use the existing stdin, stdout, and
stderr filedescriptors for the child process. Since services
presumably don't have valid file descriptors for stdin, stdout,
and stderr, you probably have to tell subprocess to use pipes
for all three.  Otherwise, it will default to using the invalid
or nonexistant file descriptors of the parent.

[If you reply, I proably won't see it.  All posts from google
groups are plonked by my newsreader configuration.  It was
somewhat of a fluke that I came across your posting.]

-- 
Grant Edwards                   grante             Yow! On the road, ZIPPY
                                  at               is a pinhead without a
                               visi.com            purpose, but never without
                                                   a POINT.



More information about the Python-list mailing list