如何使用 subprocess.Popen
运行以下命令?
mysqldump database_name table_name | bzip2 > filename
我知道os.system()
可以完成这项工作,但我不想等待转储在主程序中完成。
最佳答案
您希望 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
关于python - 使用 subprocess.Popen 运行命令管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1654600/