0

How to extract the stdout of the executed command when I use waitpid() during subprocess.Popen()?

p = subprocess.Popen(['ls'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
retcode = os.waitpid(p.pid, 0)[1]

When I use,

p.communicate()

it returns empty ('','')

ok, I use it like this now:

p = subprocess.Popen(['ls'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
err = p.stderr.read()
retcode = os.waitpid(p.pid, 0)[1]
Ibrahim Quraish
  • 3,889
  • 2
  • 31
  • 39
  • Possible duplicate of [How to run a subprocess with Python, wait for it to exit and get the full stdout as a string?](https://stackoverflow.com/questions/13398261/how-to-run-a-subprocess-with-python-wait-for-it-to-exit-and-get-the-full-stdout) – tripleee Jan 30 '19 at 13:39
  • Perhaps see also https://stackoverflow.com/a/51950538/874188 – tripleee Jan 30 '19 at 13:41

0 Answers0