在python中获取java输出

时间:2015-06-04 12:55:21

标签: java python subprocess

根据我的上一个问题here,我试图在python中运行一些java并获得结果。到目前为止,我的代码看起来像这样:

import subprocess

a = subprocess.Popen(['java -Xmx1024m -jar ./maui-standalone-1.1-SNAPSHOT.jar run /data/models/term_assignment_model -v /data/vocabulary/nyt_descriptors.rdf.gz -f skos'], cwd=r'/Users/samuelburke/Repositories/RAKE-tutorial/', shell=True, stdout=subprocess.PIPE)

out, err = a.communicate()

print out

java自身在命令行中运行时返回一些文本中的关键字列表,如下所示:

04 Jun 2015 12:49:10  INFO Vocabulary - --- Loading RDF model from the SKOS file...
04 Jun 2015 12:49:12  INFO Vocabulary - --- Building the Vocabulary index from the RDF model...
04 Jun 2015 12:49:12  INFO Vocabulary - --- Statistics about the vocabulary: 
04 Jun 2015 12:49:12  INFO Vocabulary -     498 terms in total
04 Jun 2015 12:49:12  INFO Vocabulary -     0 non-descriptive terms
04 Jun 2015 12:49:12  INFO Vocabulary -     0 terms have related terms
Keyword: Food 0.010580524344569287
Keyword: Theater 0.0022471910112359544
Keyword: Education and Schools 0.0022471910112359544
Keyword: Child Care 0.0022471910112359544
Keyword: Trees and Shrubs 0.0022471910112359544
Keyword: Sociology 0.0022471910112359544
Keyword: Wines 0.0022471910112359544
Keyword: Science and Technology 0.0022471910112359544
Keyword: Heart 0.0022471910112359544
Keyword: Evolution 0.0022471910112359544

但是,运行上面的代码会返回:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.Exception: Name of model required argument.
    at com.entopix.maui.StandaloneMain.runMaui(StandaloneMain.java:40)
    at com.entopix.maui.StandaloneMain.main(StandaloneMain.java:109)
    ... 6 more

这是我第一次做这样的事情而且我对编程很陌生,所以我想我可能会接近这一切。任何帮助非常感谢。干杯!

0 个答案:

没有答案