gpt4 book ai didi

python - 使用 subprocess.Popen 运行命令管道

转载 作者:太空狗 更新时间:2023-10-30 02:35:39 28 4
gpt4 key购买 nike

如何使用 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com