Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
From novice to tech pro — start learning today.
String envVar = System.getProperty("PROPER
However, I am guessing that you are more interested in setting rather than getting.
In short, its not possible if you run on NT, it is possible on UNIX.
The reason that its not possible on NT is that each process runs in its own process space and has no access to the process space that created it.
Therefore, if you COULD set the environment variable only YOUR process would be able to see it. No other processes would be aware of it or its value.
If all you want to do is change it in the context of the currently running process, then you could use:
String cmd = "set myEnvVar=\"Hello World\"";
Runtime.getRuntime().exec(
If you explain 'why' you need to do this in more detail, maybe I can provide you with an alternative solution.