Python - 用很多参数调用popen

mr-*_*-sk 1 python exec popen

我试图用一个参数列表调用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])
Run Code Online (Sandbox Code Playgroud)

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']
Run Code Online (Sandbox Code Playgroud)

根据: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'
Run Code Online (Sandbox Code Playgroud)

如果我将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
Run Code Online (Sandbox Code Playgroud)

即使我从终端运行此命令,它仍然有效.

$> 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
Run Code Online (Sandbox Code Playgroud)

TIA的帮助!

编辑

编辑编辑

NEVERMIND,我看到了这个问题.[]...谢谢!heheh

che*_*ner 6

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)
Run Code Online (Sandbox Code Playgroud)