2

I would like to start an external application from within a Python subprocess like this:

import subprocess
...
process = subprocess.POpen (shlex.split ("make test-scripts"),
                            env=my_environment, 
                            stdout=my_logfile, stderr=my_logfile)
result = process.wait ()

So the make command will launch another application to be tested and I'm interested in the resulting output which is captured in a log file.

That works well except if the started application spawns its own processes, too. In this case, the output of these new processes does not appear in my log file but right in the DOS shell the python script above is started from instead.

Is there a way to get the output of these "sub sub" processes, too ?

What I have already tried (but did not work):

  • Redefining sys.stdout and sys.stderr by my own listener.
  • All kinds of '2>&1' redirections.
  • Various experiments with subprocess arguments (stdout via PIPE, shell=True, ...)

The only hint in this direction I found is Capture standard output for Python child spawned by external package, but this relates to Python subprocess applications (my launched application is in C++).

Community
  • 1
  • 1
Frank Blabu
  • 181
  • 13
  • It looks like the processes spawned by your application do not (necessarily) write to the same output as the application itself. I do not think you can fix that outside the application. – Stop harming Monica Oct 07 '16 at 13:28
  • After some more evaluation, there does not seem to be a way to do this from the 'outside view'. I presume that the processes are started using 'CreateProcessW ()' in the C++ part of the application, so that [http://stackoverflow.com/questions/19051769/createprocess-redirect-child-stdout-to-parent-stdout-in-c-windows] could be an answer if I had access to the source code. – Frank Blabu Oct 10 '16 at 11:11

0 Answers0