In my python script, I need to call within a for loop an executable, and waiting for that executable to write the result on the "output.xml".
How do I manage to use wait() & how do I know when one of my executable is finished generating the result to get the result? How do I close that process and open a new one to call again the executable and wait for the new result?
import subprocess
args = ("bin/bar")
popen = subprocess.Popen(args)
I need to wait for the output from "bin/bar" to generate the "output.xml" and from there, read it's content.
for index, result in enumerate(results):
myModu开发者_StackOverflow中文版le.callSubProcess(index)
#this is where the problem is.
fileOutput = open("output.xml")
parseAndStoreInSQLiteFileOutput(index, file)
Popen.wait()
will make the script wait until the process ends. There's no need to kill the process afterwards, since it will have already exited.
I think the easiest way to do is using call
:
import subprocess
retcode = subprocess.call('command', shell=True)
It waits for the process to terminate and assign the return code to the variable. For more detailed description see 17.1.subprocess - convenience functions in the python documentation. Hope it helps.
精彩评论