可能重复:
系统属性和环境变量有什么区别
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 启动的此进程?