Reputation: 55
I have a problem dealing with Windows environment variables in a puppet (configuration management) script. My scripts deal with silent instalation of resources and configuration of their requirements (environment variables, files, etc..)
My problem comes here. One of my scripts installs a JDK in a windows system, this means install the executable, configure JAVA_HOME and JRE_HOME and include %JAVA_HOME%/bin
into %PATH%
. This is easy to perform through setx commands but has a problem when it comes to performing a second execution of the script: the PATH variable ends up being %PATH%;%JAVA_HOME%/bin;%JAVA_HOME%/bin
(and further executions will mean a longer var).
The solution to this side effect is perform the command only if %PATH% does not already contains %JAVA_HOME/bin and that could be performed through an echo %PATH% | find "%JAVA_HOME/bin"
only if variables would not be expanded by default...
I have to say, that the previous command fails because JAVA_HOME contains its version (like C:\Program Files\Java\jdk_6u30
).
So... it is possible to echo an environment variable without expanding its contents? I only need the RAW variable at find command, nothing more.
Upvotes: 2
Views: 698
Reputation: 2950
You can read the PATH directly from the registry:
reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path
This will allow to get it's value without expansion.
Upvotes: 2