简体   繁体   English

Python-使用许多参数调用popen

[英]Python - Calling popen with many arguments

I'm attempting to call popen with a list of arguments. 我试图用参数列表调用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 is: 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']

Which according to: Python OSError: [Errno 2] is the correct format. 其中根据: Python OSError:[Errno 2]是正确的格式。 However, I get the following error: 但是,出现以下错误:

  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'

If I treat the execString as a string, I get a different error: 如果我将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

Even though if I run this command from terminal, it works. 即使我从终端运行此命令,它也可以工作。

$> 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 for the help! TIA的帮助!

EDIT 编辑

EDIT EDIT 编辑编辑

NEVERMIND, I see the issue. 没关系,我看到了问题。 []...thanks! []...谢谢! heheh 呵呵

execStringList is already a list, so you can pass it directly to subprocess.Popen . 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)

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

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