capture stdout and stderror from within a Windows Service?

Chris Curvey ccurvey at
Fri May 15 08:24:03 EDT 2009

On May 14, 11:57 am, Chris Curvey <ccur... at> 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"]

Ahhh, Blake put me on the right track.  If you want any of the
streams, you have to supply values for all of them, like so:

p = subprocess.Popen(step, shell=True

(stdout, stderr) = p.communicate()

and, incidentally, it appears that you have to use UNC paths in your
Popen call -- drive letters won't work.

so "dir \\foobar\myshare\mydir" will work, but "dir j:\mydir" will

Many thanks for all your assistance.

More information about the Python-list mailing list