Call a Java application with a "subprocess" from Python and read the output of a Java application

What is the best way to read the result (i.e. via System.out.println) of a Java application that is called from Python using

subprocess.Popen("java MyClass", shell=True) 

without writing and reading a file? (Using Jython etc. is not a possible solution)

+4
source share
2 answers
 p1 = subprocess.Popen(["/usr/bin/java", "MyClass"], stdout=subprocess.PIPE) print p1.stdout.read() 
+5
source

I found a solution:

 p = subprocess.Popen("java MyClass", shell=True, stdout=subprocess.PIPE) output, errors = p.communicate() 

S.Mark is good too!

+3
source

Source: https://habr.com/ru/post/1303273/


All Articles