简体   繁体   中英

Java Process: What is the Environment?

I'm reading:

http://docs.oracle.com/javase/8/docs/api/java/lang/ProcessBuilder.html

which links to

http://docs.oracle.com/javase/8/docs/api/java/lang/System.html#getenv--

Which states that System.getEnv() returns:

Returns an unmodifiable string map view of the current system environment. The environment is a system-dependent mapping from names to values which is passed from parent to child processes.

I'm not sure I understand this sentence. What are the names-values mapped? Is it the variables defined by my program and the java runtime required to support it? Why are they important?

Depending on your operating system (thus system-dependent ) you may set these environment variables in various ways.

On Windows you may use eg the "Environment variables" button from the "System properties" window to add, delete or modify an environment variable.

Tell us about your OS and you may get further information.

These variables are important because the are one way to parametrize your processes (or slightly inaccurate "your programs").

Usually, when one process spawns another child process, you have the option to let the child process inherit these variables (as a kind of "starting point").

Using Map<String, String> env = System.getenv(); you get a map of the environment variables; they have nothing to do with the variables you define in your program, though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM