gpt4 book ai didi

Python - 使用许多参数调用 popen

转载 作者:太空宇宙 更新时间:2023-11-04 08:15:57 35 4
gpt4 key购买 nike

我正在尝试使用参数列表调用 popen。

    execString = "java -jar {} {} {} {} {} {}".format(os.path.join(config.java_root,
config.java_jar),
self.canvasSize,
self.flightId,
self.domain,
self.defPath,
self.harPath)
execStringList = execString.split()
print execStringList
subprocess.Popen([execStringList])

execStringList 是:

['java', '-jar', '/Users/me/Projects/reporting-test/build/clickunit-0.1.jar', '300x1050', '123', 'dev.me.net', '/Users/me/Projects/reporting-test/src/definitions/300x1050.yml', '/Users/me/Projects/reporting-test/out/01/15112']

根据:Python OSError: [Errno 2]是正确的格式。但是,我收到以下错误:

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 672, in __init__
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1202, in _execute_child
AttributeError: 'list' object has no attribute 'rfind'

如果我将 execString 视为一个字符串,我会得到一个不同的错误:

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 672, in __init__
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1202, in _execute_child
OSError: [Errno 2] No such file or directory

即使我从终端运行这个命令,它仍然有效。

$> java -jar /Users/me/Projects/reporting-test/build/clickunit-0.1.jar 300x1050 123 dev.me.net /Users/me/Projects/reporting-test/src/definitions/300x1050.yml /Users/me/Projects/reporting-test/out/01/3727

TIA 寻求帮助!

编辑

编辑编辑

没关系,我明白了这个问题。 []...谢谢!呵呵

最佳答案

execStringList 已经是一个列表,所以你可以直接将它传递给 subprocess.Popen

execString = "java -jar {} {} {} {} {} {}".format(os.path.join(config.java_root,
config.java_jar),
self.canvasSize,
self.flightId,
self.domain,
self.defPath,
self.harPath)
execStringList = execString.split()
print execStringList
# Pass execStringList directly to Popen
subprocess.Popen(execStringList)

关于Python - 使用许多参数调用 popen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14507094/

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