0

i want to set a jvm variable with any of the Windows environment variables, say suppose WINDIR. ie is there way i can set as -Dwindir=WINDIR where the windir will have the value of WINDIR.

EDIT: when tried with -Dwindir=WINDIR it is directly assigning a string value of "WINDIR" which i am not interested in.

Thanks.

2 Answers 2

2

First if you want to pass environment variable to JVM on windows use % sign: -Dwinddir=%WINDIR%. This is not java. This is DOS.

Second, you do not need it in most cases. Use System.getenv() instead. Probably it contains all you need.

Sign up to request clarification or add additional context in comments.

Comments

1

Enclosing the environment variable in percent signs should do it:

-Dwindir=%WINDIR%

3 Comments

Care to tell HOW it didn't work? Or should we ask our crystal ball?
i had given in vm arguments like -Dwindir=%WINDIR% and using the variable windir in the logj.properties to name the file. its creating a file with the name %WINDIR%.
In that case I suspect you will find that WINDIR is not defined as an environment variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.