When I execute a python script using subprocess.Popen(script, shell=True) in another python script, is it possible to alert python when the script completes running before executing other functions?
On a side note, can I get real-time output of the executed python script?
I can only get output from it doing command>output.txt but that’s only after the whole process ends. stdout does not grep any ouput.
When you create a subprocess with Popen, it returns a
subprocess.Popenobject that has several methods for accessing subprocess status and data:poll()to determine whether a subprocess has finished.Noneindicates that the process has ended.communicate().You can combine these two to create a script that monitors output from a subprocess and waits until its ready as follows: