python 调用java

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())

  

 

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

posted @ 2023-04-17 07:22  西北逍遥  阅读(98)  评论(0编辑  收藏  举报