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..)
我在puppet(配置管理)脚本中处理Windows环境变量时遇到问题。我的脚本处理资源的静默安装和他们的需求配置(环境变量,文件等)。
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).
我的问题来了。我的一个脚本在Windows系统中安装JDK,这意味着安装可执行文件,配置JAVA_HOME和JRE_HOME并将%JAVA_HOME%/ bin包含在%PATH%中。这很容易通过setx命令执行,但在执行第二次执行脚本时遇到问题:PATH变量最终为%PATH%;%JAVA_HOME%/ bin;%JAVA_HOME%/ bin(以及进一步执行将意思是更长的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...
这种副作用的解决方案是仅当%PATH%尚未包含%JAVA_HOME / bin并且可以通过echo%PATH%|执行时才执行该命令。只有在默认情况下不扩展变量时才能找到“%JAVA_HOME / bin”
I have to say, that the previous command fails because JAVA_HOME contains its version (like C:\Program Files\Java\jdk_6u30
).
我不得不说,上一个命令失败,因为JAVA_HOME包含其版本(如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.
那么......有可能在不扩展其内容的情况下回显环境变量吗?我只需要在find命令中使用RAW变量,仅此而已。
1 个解决方案
#1
0
You can read the PATH directly from the registry:
您可以直接从注册表中读取PATH:
reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path
This will allow to get it's value without expansion.
这样就可以在没有扩展的情况下获得它的价值。
#1
0
You can read the PATH directly from the registry:
您可以直接从注册表中读取PATH:
reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path
This will allow to get it's value without expansion.
这样就可以在没有扩展的情况下获得它的价值。