I followed the SO Answer to execute a java program from python
import os.path
import 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', '-cp', 'model/classification', java_class]
process = subprocess.Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT, universal_newlines=True)
stdout, stderr = process.communicate(stdin)
compile_java(os.path.join('model', 'classification', 'Model.java'))
execute_java('Model', '5 5 5 5 5 5 5')
My problem is, that in the main method of my java program String[]args
is empty. My input sequence of 5 5 5 5 5 5 5
does not reach the java program.
Calling java Model 5 5 5 5 5 5 5
from the console works as expected