I\'m writing a python script that uses subprocess.Popen to execute two programs (from compiled C code) which each produce stdout. The script gets that output and saves it to
You could call .wait() on each Popen object in order to be sure that it's finished and then call log.flush(). Maybe something like this:
def run(cmd, logfile):
p = subprocess.Popen(cmd, shell=True, universal_newlines=True, stdout=logfile)
ret_code = p.wait()
logfile.flush()
return ret_code
If you need to interact with the Popen object in your outer function you could move the .wait() call to there instead.