在Java中访问shell环境变量 [英] Access shell environment variables in Java
问题描述
访问ProcessBuilder环境
您可以通过获取创建程序时存在的环境变量System.getenv()
:
http://download.oracle.com/javase/tutorial/essential/environment/env.html
当Java应用程序使用ProcessBuilder对象创建新进程时,传递给新进程的默认环境变量集与提供给应用程序的虚拟机进程的集合相同。应用程序可以使用ProcessBuilder.environment更改此集。
您的子进程应该自动获取您的环境。
Does anyone know how to access the environment variables of the standard shell environment in Java? I am using the ProcessBuilder class and I have to specify specific environment variables used in a shell script I am running, these variables exist in the standard shell environment.
Accessing ProcessBuilder environment does not work.
You can get at the environment variables that existed when your program was created through 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.
It looks like your child process should get your environment automatically.
这篇关于在Java中访问shell环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!