天天看點

python腳本裡執行jar包_Python:如何通過python腳本執行jar檔案

python腳本裡執行jar包_Python:如何通過python腳本執行jar檔案

I have been looking for an answer for how to execute a java jar file through python and after looking at:

I tried to do the following (both my jar and python file are in the same directory):

import os

if __name__ == "__main__":

os.system("java -jar Blender.jar")

and

import subprocess

subprocess.call(['(path)Blender.jar'])

Neither have worked. So, I was thinking that I should use Jython instead, but I think there must a be an easier way to execute jar files through python.

Do you have any idea what I may do wrong? Or, is there any other site that I study more about my problem?

解決方案

I would use subprocess this way:

import subprocess

subprocess.call(['java', '-jar', 'Blender.jar'])

But, if you have a properly configured /proc/sys/fs/binfmt_misc/jar you should be able to run the jar directly, as you wrote.

So, which is exactly the error you are getting?

Please post somewhere all the output you are getting from the failed execution.