Answers for "recieve output from java python"

0

recieve output from java 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]
    proc = subprocess.Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
    stdout,stderr = proc.communicate(stdin)
    return stdout

compile_java('helloworld.java')
java_output = execute_java('helloworld.java', 'args')
Posted by: Guest on May-04-2021

Python Answers by Framework

Browse Popular Code Answers by Language