在Java中访问shell环境变量

有谁知道如何在Java中访问标准shell环境的环境变量?我正在使用ProcessBuilder类,我必须指定我正在运行的shell脚本中使用的特定环境变量,这些变量存在于标准shell环境中.

访问ProcessBuilder环境不起作用.

您可以获取通过System.getenv()创建程序时存在的环境变量:

http://download.oracle.com/javase/tutorial/essential/environment/env.html

When a Java application uses a ProcessBuilder object to create a new process, the default set of environment variables passed to the new process is the same set provided to the application’s virtual machine process. The application can change this set using ProcessBuilder.environment.

您的子进程看起来应该自动获取您的环境.

https://stackoverflow.com/questions/3959521/access-shell-environment-variables-in-java

转载注明原文:在Java中访问shell环境变量