positron
positron

Reputation: 3693

Environment variable does not show up when executing set command

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?

Upvotes: 0

Views: 3919

Answers (2)

positron
positron

Reputation: 3693

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.

Upvotes: 1

sevensevens
sevensevens

Reputation: 1750

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");

Upvotes: 0

Related Questions