1

引数のリストを使用して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 :[Errno2]が正しい形式です。ただし、次のエラーが発生します。

  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!

編集

編集編集

決して気にしないでください、私は問題を見ます。[]...ありがとう!ふふ

4

1 に答える 1

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)
于 2013-01-24T17:25:25.473 に答える