注意点: 1.保证python能用命令行执行 2.python里的路径必须是绝对路径。(重要)
public class Demo1 {
public static void main(String[] args) {
Process proc;
try {
proc = Runtime.getRuntime().exec("python C:\\project_of_python\\people_face\\train.py");
BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
System.out.println(in.readLine());
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
proc.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
|