因为没有设置到Python的系统环境变量,所以执行Python脚本时,要设置
public static void main(String[] args) {
String[] cmdarray = new String[] { "cmd", "/c", "python D:\\python2\\test.py"};
String[] envp = new String[] {"path=D:\\Anaconda3\\envs\\leantwo"};
try {
Process process = Runtime.getRuntime().exec(cmdarray, envp);
BufferedReader in = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
int re = process.waitFor();
System.out.println(re);
} catch (Exception e) {
e.printStackTrace();
}
}