package com.iailab.module.data.video.hikvision.utils; import lombok.extern.slf4j.Slf4j; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; /** * @author PanZhibao * @Description * @createTime 2023年01月11日 11:03:00 */ @Slf4j public class PythonUtil { public static List execPy(String[] command) { List lines = new ArrayList<>(); try { Process proc = Runtime.getRuntime().exec(command); BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream(),"GBK")); String line = null; while ((line = in.readLine()) != null) { log.info(line); lines.add(line); } // 0表示成功,1表示远程调用失败,2表示python脚本出错 int waitFor = proc.waitFor(); log.info("waitFor=" + waitFor); if (waitFor != 0) { throw new Exception("调用python失败"); } } catch (Exception ex) { ex.printStackTrace(); log.error(ex.getMessage()); log.error("运行python异常!command=" + command.toString()); } return lines; } }