python 调用java

发布时间 2023-04-17 07:29:30作者: 西北逍遥

python 调用java

 

import subprocess

# Replace "path/to/java/program" with the actual path to your Java program
java_program_path = "path/to/java/program"

# Replace "arg1" and "arg2" with the actual arguments to your Java program
args = ["arg1", "arg2"]

# Call the Java program
process = subprocess.Popen(["java", "-jar", java_program_path] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

# Wait for the process to finish and get the output
stdout, stderr = process.communicate()

# Print the output
print(stdout.decode())

  

 

##############