Execute command, show its output, get its exit code
You want to execute an external program, show its output, and get its exit code at the end.
import shlex from subprocess import Popen, PIPE cmd = "..." process = Popen(shlex.split(cmd), stdout=PIPE) process.communicate() # execute it, the output goes to the stdout exit_code = process.wait() # when finished, get the exit code
Example: I used this code with FFmpeg. FFmpeg updates the output on the stdout regularly while doing a conversion. At the end I can ask if the conversion was successful (
exit_code == 0) or not.