可能的复制品:
System 属性和环境变量 的区别是什么
System.getenv ()和 System.getProperty ()之间的区别是什么?
当我们使用 ProcessBuilder 运行任何命令时,我们可以设置环境变量,即:
String[] vCmd = { System.getenv("ANT_HOME") + "/bin/ant", "-f",
ANT_BUILD_FILE, TARGET };
ProcessBuilder pb = new ProcessBuilder(vCmd);
Map<String, String> env = pb.environment();
env.put("CLASSPATH",
antHome+"/lib/ant.jar:"
+ antHome+"/lib/ant-launcher.jar:"
+ antHome+"/lib/ant-nodeps.jar:"
);
try{
Process process = pb.start();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
pb.wait();
}
catch(Exception e)
System.out.println(e.getMessage());
}
如果我在此方法之前使用 System.setProperties ()设置一些属性,它是否可用于由 ProcessBuilder 启动的此进程?