System.getenv() 和 System.getProperty() 之间的区别
2022-08-31 10:07:39
可能的重复:
系统属性和环境变量之间有什么区别
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 启动的此过程?