Is there a way to check if a subprocess has finished its job? My python script executes an 123.exe from cmd. 123.exe then does some things and in the end it writes 1 or 0 to a txt file. Python script then reads the txt file and continues with the job if ‘1’ and stops if ‘0’. At the moment all that I can think of, is to put the python script to sleep for a minute. That way the 123.exe has most certainly written 1 or 0 into the txt file. This realization is very simple but at the same time stupid.
So my question is, is there a way to deal with this problem without the need for timeout? A way to make the python script to wait til the 123.exe stops?
Use:
This will execute the command, wait until it finishes, and you get its return code into
retcode(this way you could also avoid the need of checking the output status file, if the command returns a proper return code).If you need to instantiate manually the
subprocess.Popen, then go for(and then check
Popen.returncode).