使用“子进程”调用Java应用程序从Python和阅读Java应用程序输出 [英] Calling Java app with "subprocess" from Python and reading the Java app output
本文介绍了使用“子进程”调用Java应用程序从Python和阅读Java应用程序输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
读取Java应用程序的输出(即通过System.out.println)最好的方法是从Python调用
What is the nicest way to read the output (i.e. via System.out.println) of a Java app which is called from Python with
subprocess.Popen("java MyClass", shell=True)
无需写入和读文件? (使用Jython等不是一种可能的解决方案)
without writing and reading a file? (Using Jython etc is not a possible solution)
推荐答案
p1 = subprocess.Popen(["/usr/bin/java", "MyClass"], stdout=subprocess.PIPE)
print p1.stdout.read()
这篇关于使用“子进程”调用Java应用程序从Python和阅读Java应用程序输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文