I want to run an external program from python, redirect output (lots of text) to a log file and wait for that program to finish. I know I can do it via bash:
#! /bin/bash
my_external_program > log_file 2>&1
echo "done"
But how can I do the same with python? Note that with the bash command, I can check the log_file while the program is running. I want this property in python as well.
解决方案
You can check the link above, it is indeed similar issue. Using Popen from subprocess or from os.popen it is possible to check real time.
With a simple os.system ("your script > /tmp/mickey.log") will also run the script, but it will wait the execution of the command before.
Please let me know if this solve your issue.