1

When these lines are executed in my Python script:

a = ['python', '-v']
finishedProcess = subprocess.run(a, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)

both finishedProcess.stdout and finishedProcess.stderr are empty, and finishedProcess.returncode is 0. As you can see, I am even combining both stderr and stdout into the stdout variable.

I can run the same command directly from the command line and get output.

I have been following the directions from this posting: Running shell command and capturing the output

What am I doing wrong here? My Python version is 3.7.6.

Joey Kleingers
  • 297
  • 1
  • 4
  • 13
  • Edit: I got rid of `shell=True` and now it works, but I don't understand why it works. After reading the docs, I still don't really get what the shell option does. – Joey Kleingers Sep 09 '20 at 16:13
  • Just ran the code on Win10 with Python 3.7.7 and got output in both cases (`shell=True` and `shell=False`). May it be environment specific issue? –  Sep 09 '20 at 16:27
  • Yep, seems that way. Will need to keep debugging it. It's good to hear that it should work both ways though. – Joey Kleingers Sep 09 '20 at 16:30
  • Any more on this issue? I am facing the same and I keep getting None out of stdout, while I am sure there is some output. – AndreaCassioli Jan 27 '23 at 09:47

0 Answers0