0

One of our applications relies on existence of environment variable that is being set by our server installation. After installing the server I can confirm presence of this variable using 'Environment Variables' dialog. However, when client application executes, calls to set command and Java's System.getenv() method omit this variable, all others are present. What's interesting is that this failure to read particular environment variable only happens on Windows 7 64-bit machine, on Windows XP 32-bit this does not happen. The same code on 32-bit machine returns environment variable set by our server installation. I am not sure if difference between Windows 7 and Windows XP plays role here. Does anybody have any suggestions on how to approach this issue?

2
  • getEnv returns a case sensitive based map on all platforms. BTW, what is the outcome of System.getProperties()? Does is contain the env variable you are searching for? Commented Aug 29, 2013 at 17:20
  • @Ravinder it does not. I suppose because mine is not a system property? Commented Aug 29, 2013 at 17:56

2 Answers 2

1

It turns out, and I didn't know this, Windows 7 has two cmd.exe commands - one for 32-bit and one for 64-bit environment. When I was running cmd.exe for 32-bit environment I did not see my variable, but when I ran cmd.exe for 64-bit environment, the variable was there.

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

Comments

0

A couple of things to check

1) what happens when you type echo %VARNAME% it is likely not too far from what Java is doing behind the scenes.

2) Is this a system wide environmental variable or a per user one? It shouldn't make a difference but it might

3) Can you post your code. The below snippit worked fine for me, does this work for you?

String path = System.getenv("PATH");

1 Comment

1) No output is printed and when I execute set command my variable, which is a system variable is not printed. 2) It's a system variable 3) This is the code I am using and both produce same result: p = r.exec("cmd.exe /c set"); //$NON-NLS-1$ Map<String, String> getenv = System.getenv();

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.