Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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')
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #recieve #output #java #python
ADD COMMENT
Topic
Name
8+6 =