0
Can anyone help me ,,,,,,, ,,how I can combine Java and python at a single program ,,,,,,,,,,,,,,,or is it even possible
Cuz I want to create super program,,,,,,, ,,,,, I wa nt to create AI like Tony Stark's Jarvis with my friends who are learning another language
1 Antwort
+ 1
You can do this by using one of the languages to execute the other through the command line:
Python:
# Using the `os` module:
import os
os.system("java -jar MyJarFile.jar")
# Or (still with `os`):
s = os.popen("java -jar MyJarFile.jar")
output = s.read()
print(output) # Prints output from running command.
# Using the `subprocess` module (for a bit more control):
import subprocess
process = subprocess.Popen(['java', '-jar', 'MyJarFile.jar'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
Running python with java:
See this: https://www.edureka.co/community/358/how-to-execute-a-python-file-with-few-arguments-in-java