I followed the SO Answer to execute a java program from python
import os.path, subprocess
from subprocess import STDOUT, PIPE
def compile_java(java_file):
subprocess.check_call(['javac', java_file])
def execute_java(java_file, stdin):
java_class, ext = os.path.splitext(java_file)
cmd = ['java', java_class]
process = subprocess.Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT, universal_newlines=True)
stdout, stderr = process.communicate(stdin)
print(stdout)
compile_java(os.path.join('model', 'classification', 'Model.java'))
execute_java('Model', '5 6 7 8')
The python code compiles the /model/classification/Model.java
without problems. But when the python code executes the java program, Java can not find or load the main class Model. Executing java Model
in the command line in the same directory (with the compiled version, which was triggered by the python snippet above) works.