Last active
September 20, 2022 23:05
-
-
Save voodoonofx/8e5bcae8e0b0c5741148 to your computer and use it in GitHub Desktop.
subprocess.Popen Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
cmd = ['/full/path/to/python', '/full/path/to/your/process'] | |
print('running command: "{0}"'.format(cmd)) # output the command. | |
# Here, we join the STDERR of the application with the STDOUT of the application. | |
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
outLines = [] # We use this just in case you want to see the output of the program later. It's not required. | |
for line in iter(process.stdout.readline, ''): | |
print line.rstrip() | |
outLines.append(line) # Again, only if you need it | |
returncode = process.wait() # Wait for the underlying program to finish normally. | |
print('sub-process exited with code: {0}'.format(returncode)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In python3, update line 9 to the following: