public static void main(String[] args) {
String result = "";
String[] arguments = new String[] {"python", "D:\WuTong\BanGong\PyCharmWork\OC\Test2\Demo01\Test2.py"};
try{
//"cmd /c [your command]"+
Process process = Runtime.getRuntime()
.exec(arguments);
InputStreamReader ir = new InputStreamReader(process.getInputStream(),"GBK");
LineNumberReader input = new LineNumberReader(ir);
result = input.readLine();
input.close();
ir.close();
int re = process.waitFor();
//错误码 1是错误 0是正确
System.out.println(re);
System.out.println(result);
} catch (IOException | InterruptedException e) {
System.out.println("调用python脚本并读取结果时出错:" + e.getMessage());
}
}
借鉴:
Java(springboot)调用python脚本(包含调用第三方库的脚本)_飞向远方的猪的博客-CSDN博客_springboot调用python
使用Runtime去运行命令行 CreateProcess error=193, %1 不是有效的 Win32 应用程序。_agoodcoolman的博客-CSDN博客_createprocess error=193
Java调用Python脚本无法得到运行结果_吕小呆呆的博客-CSDN博客_java调用python没反应
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)