public static void execPythonShell(File file) throws IOException {
String path = Utils.class.getClassLoader().getResource(“/import.py”)
.getPath();
Runtime runtime = Runtime.getRuntime();
BufferedReader br = null;
try {
String[] cmds = new String[] {
"/bin/sh",
"-c",
"cd " + path + "&&python edit_support_export_infor.py "
+ file.getPath() };
Process process = runtime.exec(cmds);
br = new BufferedReader(new InputStreamReader(
process.getInputStream(), "GBK"));
String tmp = null;
while ((tmp = br.readLine()) != null) {
System.out.println("Shell Message : " + tmp);
}
} catch (IOException e) {
logger.error(e);
} finally {
br.close();
}
}
// -c 意思是执行完成自动关闭,这里多条linux命令通过&&连接到一起