What is the best/foolproof way to get the values of environment variables in Windows when using J2SE 1.4 ?
You can use getEnv() to get environment variables:
String variable = System.getenv("WINDIR");
System.out.println(variable);
I believe the getEnv() function was deprecated at some point but then "undeprecated" later in java 1.5
ETA:
I see the question now refers specifically to java 1.4, so this wouldn't work for you (or at least you might end up with a deprecation warning). I'll leave the answer here though in case someone else stumbles across this question and is using a later version.
There's a switch to the JVM for this. From here:
Start the JVM with the "-D" switch to pass properties to the application and read them with the System.getProperty() method.
SET myvar=Hello world
SET myothervar=nothing
java -Dmyvar="%myvar%" -Dmyothervar="%myothervar%" myClass
then in myClass
String myvar = System.getProperty("myvar");
String myothervar = System.getProperty("myothervar");
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