java执行python文件并传参数接收python打印的消息
无情
阅读:853
2021-04-01 11:06:03
评论:0
1.python文件
import sys
import time
if __name__ == '__main__':
a = int(sys.argv[1])+3
b = int(sys.argv[2])+3
print(a)
time.sleep(5)
print(b)
2.java方法
public static void main(String[] args) {
System.out.println(new Date());
Process proc;
try {
proc = Runtime.getRuntime().exec("python E:\\work\\svn\\电商\\main\\testLog.py 1111 2222");// 执行py文件
//用输入输出流来截取结果
BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(new Date() +"=="+line);
}
in.close();
proc.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
3.控制台输出

声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。



