简体   繁体   中英

How to execute a .class file(java) from .py script?

I was doing a project on my RaspberyPi, when I stumbled onto this problem: I need a python script to run a java file, but can't find a way to do that. The files are start.py and main.class and are in the same folder.

What you want to do is use python to execute a bash command (assuming you're on linux), you'd use the same command to run a java file which is java main where main is main.class

here's a simple script that uses subprocess to run the command

import subprocess


cmd = 'java main'.split(' ')
subprocess.run(cmd)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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