Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

excute .jar file from python

Im trying to access server data via a jar-file. Doing this in MATLAB is quite simple:

javaaddpath('*PATH*\filename.jar')
WWS=gov.usgs.winston.server.WWSClient(ip,port);
Data = eval('WWS.getRawData(var1,var2,var3)');
WWS.close;

Problem is that I need to execute this in Python and I can't figure out how to translate these few lines of code. I've tried using the subprocess module like:

WWS=subprocess.call(['java', 'gov/usgs/winston/server/WWSClient.class'])

but the best I can get is the error "could not find or load main class gov.usgs.winston.server.WWSClient.class"

Thankful for all the help!

like image 434
Alexander Hebbe Avatar asked Dec 20 '25 12:12

Alexander Hebbe


1 Answers

Also you can use the following code:

import subprocess

command = "java -jar <*PATH*\filename.jar>"
result = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()

And result is the output of the jar file.

like image 60
OmG Avatar answered Dec 22 '25 01:12

OmG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!