0

I am automating a GUI application that also has a CLI. I can successfully run the following (theApplication is an internally developed app):

import subprocess
process = subprocess.Popen(r'theApplication.exe -foo=7') 

It then prints its output which I wish to process, so I use subprocess.PIPE

import subprocess
process = subprocess.Popen(r'theApplication.exe -foo=7', stdout=subprocess.PIPE) 

Now the program does not start and Windows reports that theApplication has stopped working. The same happens if the stdout is redirected to DEVNULL or a file. I tried setting bufsize to 0 and 1 and the same happens.

Tried all permutations with stdout and stderr being redirected or not. It only works if neither of them is redirected. If one is redirected it instantly breaks the program. The value of process.returncode is None.

How can pipeing the output can break the program?

handras
  • 1,259
  • 9
  • 21

2 Answers2

0

Have you already tried it with list parameter? Like:

import subprocess
process = subprocess.Popen(["theApplication.exe", "-foo=7"], stdout=subprocess.PIPE) 
milanbalazs
  • 3,728
  • 4
  • 13
  • 34
  • I tried it just now, and it produces the same error. – handras May 15 '19 at 10:19
  • Perhaps you should define stderr as PIPE as well and check it. Furthermore you can check the return code of your command. Eg.: process.returncode. On the other hand I think the problem is in theApplication.exe not in subprocess. – milanbalazs May 15 '19 at 10:42
  • Tried all permutations with stdout and stderr being redirected or not, does not matter. The returncode is `NoneType`. So definitly the process does not start. The question now is how pipeing can break the program. – handras May 15 '19 at 11:49
  • Could you try the following implementation? `import subprocess` `process = subprocess.Popen(["theApplication.exe", "-foo=7"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) ` `out, err = process .communicate()` – milanbalazs May 15 '19 at 11:55
0

So the answer was to also redirect stdin=subprocess.PIPE, altough the theApplication does not read from it.

handras
  • 1,259
  • 9
  • 21