简体   繁体   English

使用subprocess.Popen运行命令管道

[英]Run command pipes with subprocess.Popen

How can I run the following command using subprocess.Popen ? 如何使用subprocess.Popen运行以下命令?

mysqldump database_name table_name | bzip2 > filename

I know os.system() can do the job but I dont want to wait for the dump to finish in main program. 我知道os.system()可以完成这项工作,但我不想等待转储在主程序中完成。

You want the shell=True option to make it execute shell commands: 您希望shell=True选项使其执行shell命令:

import subprocess
subprocess.Popen("sleep 4s && echo right thar, right thar",shell=True);
print 'i like it when you put it'

which yields: 产量:

 I like it when you put it
 [4 seconds later]
 right thar, right thar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM