Runtime.getRuntime().execメソッドenvp設定システム環境変数パラメータの使用
719 ワード
Pythonのシステム環境変数が設定されていないため、Pythonスクリプトを実行する場合は、
参考資料1参考資料2参考資料3
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();
}
}
参考資料1参考資料2参考資料3