我的Java JAR在linux命令行中运行良好,我希望通过python脚本执行它。
尝试Popen
时出现以下错误:
Error: Could not find or load main class jar
有什么想法吗?
到目前为止我尝试过的事情:
Popen
包含简单的java
和-version
。检查。cwd
。检查。使用Java调用:
>>> javaCall = subprocess.Popen(['java', '-version'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
命令失败:
>>> javaCall = subprocess.Popen(['java', 'jar' ,
'abs/path/to/jar/abc.jar',
'arg 1', 'arg 2', 'arg 3'], cwd =
'/abs/path/where/jar and python files live', stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>> output, err = javaCall.communicate()
>>> print err
Error: Could not find or load main class jar
我错过的任何指示?
答案 0 :(得分:1)
在jar前面缺少一个
javaCall = subprocess.Popen(['java', 'jar' ,
'abs/path/to/jar/abc.jar',
'arg 1', 'arg 2', 'arg 3'], cwd =
'/abs/path/where/jar and python files live', stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>> output, err = javaCall.communicate()
>>> print err
Error: Could not find or load main class jar
更改为:javaCall = subprocess.Popen(['java', '-jar' , ~~~