System.getenv(name)
needs the name of environment variable.
I am trying to call Runtime.exec(String[], String[], File),
the secondary parameter need an array of environment variable, I am not sure whether subprocess will inherit environment variables from current process if I specified this parameter.
For example, if I pass new String[]{"NEWDIR=/home"}
as secondary parameter and current java process has environment OLDDIR=/var
, what is the return value of System.getenv("OLDDIR")
in the subprocess?
updated: Sorry, I have to use Java 1.4 and it seems that System.getenv()
was introduced in 1.5?
To list all the environment variables, use the command " env " (or " printenv "). You could also use " set " to list all the variables, including all local variables.
On the Windows taskbar, right-click the Windows icon and select System. In the Settings window, under Related Settings, click Advanced system settings. On the Advanced tab, click Environment Variables.
Like properties in the Java platform, environment variables are key/value pairs, where both the key and the value are strings. The conventions for setting and using environment variables vary between operating systems, and also between command line interpreters.
The System class in Java provides a method named System. getenv() which can be used to get the value of an environment variable set in the current system.
Map<String, String> env = System.getenv(); for (String envName : env.keySet()) { System.out.format("%s=%s%n", envName, env.get(envName)); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With