如何使用subprocess.Popen
运行以下命令?
mysqldump database_name table_name | bzip2 > filename
我知道os.system()
可以完成这项工作,但我不想等待转储在主程序中完成。
答案 0 :(得分:6)
您希望shell=True
选项使其执行shell命令:
import subprocess
subprocess.Popen("sleep 4s && echo right thar, right thar",shell=True);
print 'i like it when you put it'
产生:
I like it when you put it
[4 seconds later]
right thar, right thar