swingsoneto
swingsoneto

Reputation: 65

How to automatically get returncode from Popen after terminating child process?

I have a Python 3 question. How do I automatically get the returncode from a Popen object after the child process terminates?

In short, I need an application to wait, but not be unresponsive (if possible), until the child process ends, and then automatically call a function based on the returncode.

Upvotes: 1

Views: 361

Answers (1)

user2438477
user2438477

Reputation:

The following "might" be what you're looking for, but it's possible I don't quite understand what you want.

import subprocess
child = subprocess.Popen(do_something_here)
streamdata = child.communicate()[0]
rc = child.returncode

You can find more information about this here:

http://docs.python.org/2/library/subprocess.html#subprocess.Popen.returncode

If I misunderstood your question, please let me know and I'll try and help you more with this.

Upvotes: 1

Related Questions