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调用带第三方库的Python
最新推荐文章于 2024-05-12 23:16:52 发布