gpt4 book ai didi

python - 如何使用子进程popen Python

转载 作者:IT老高 更新时间:2023-10-28 21:11:36 25 4
gpt4 key购买 nike

由于 os.popensubprocess.popen 取代,我想知道如何转换

os.popen('swfdump /tmp/filename.swf/ -d')

subprocess.popen()

我试过了:

subprocess.Popen("swfdump /tmp/filename.swf -d")
subprocess.Popen("swfdump %s -d" % (filename)) # NOTE: filename is a variable
# containing /tmp/filename.swf

但我想我没有正确地写出来。任何帮助,将不胜感激。谢谢

最佳答案

subprocess.Popen 接受参数列表:

from subprocess import Popen, PIPE

process = Popen(['swfdump', '/tmp/filename.swf', '-d'], stdout=PIPE, stderr=PIPE)
stdout, stderr = process.communicate()

甚至还有一个 section of the documentation致力于帮助用户从os.popen迁移到subprocess

关于python - 如何使用子进程popen Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12605498/

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