简体   繁体   English

如何在python中运行jar文件

[英]How to run jar files in python

How can I call this jar from python and also capture the results: 如何从python调用此jar并捕获结果:

c:> java -cp "C:\\mallet-2.0.7\\class;C:\\mallet-2.0.7\\lib\\mallet-deps.jar" cc.mallet.fst.SimpleTagger --model-file nouncrf sample.txt c:> java -cp“ C:\\ mallet-2.0.7 \\ class; C:\\ mallet-2.0.7 \\ lib \\ mallet-deps.jar” cc.mallet.fst.SimpleTagger --model-file nouncrf示例。文本

Use subprocess: 使用子流程:

from subprocess import call
call(["java", "-jar", "foo.jar"])

You could also add other arguments like -cp to the list: 您还可以将其他参数(例如-cp添加到列表中:

call(["java", "-cp", "<yourclasspath>", "-jar", "foo.jar"])

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

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