Runtime.getRuntime().exec方法envp设置系统环境变量参数的使用

因为没有设置到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();
		}
	}

参考资料1
参考资料2
参考资料3

你可能感兴趣的:(python)