CMD环境变量未在PATH变量中展开 [英] CMD enviroment variables not expanded in PATH variable

查看:352
本文介绍了CMD环境变量未在PATH变量中展开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的系统偏好设置中设置了一些环境变量(Windows 8.1)。如果我启动cmd.exe并执行此命令:

I've some enviroment variables set in my sistem preferences (Windows 8.1). If i start cmd.exe and execute this commands:

C:\Users\Carlo>echo %GRAILS_HOME%
D:\Grails

C:\Users\Carlo>echo %GRADLE_HOME%
D:\Gradle

C:\Users\Carlo>echo %GROOVY_HOME%
D:\Groovy

C:\Users\Carlo>echo %PATH%
C:\ProgramData\Oracle\Java\javapath;c:\Program Files (x86)\Intel\iCLSClient\;
c:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;
C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;
C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;
C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;
C:\Program Files (x86)\Brackets\command;%GRAILS_HOME%\bin;%GRADLE_HOME%\bin;
%GROOVY_HOME%\bin

为什么最后三个变量没有在PATH中展开?

Why the last three variables is not expanded in PATH?

完成PATH变量是:

C:\ProgramData\Oracle\Java\javapath;c:\Program Files (x86)\Intel\iCLS Client\;c:\Program Files\Intel\iCLS Client\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Brackets\command;%GRAILS_HOME%\bin;%GRADLE_HOME%\bin;%GROOVY_HOME%\bin


推荐答案

环境变量(EnvVars) 它们有一个名称和一个值(在Windows中的值是一个字符串)。

Environment variables (EnvVars) are simply what their name state: variables; They have a name and a value (in Windows the value is a string).

因此,在您的示例中,名称为 PATH ,值为您列出的字符串。 OS(命令解释器)不知道EnvVar值的语义,所以当它扩展var名称时,它只是显示其值。它不分析值,并递归地展开可能存在的任何其他变量。

So in your example the name is PATH and the value is the string you listed. The OS (command interpreter) doesn't have any idea about the semantics of the EnvVar value so when it expands the var name it just shows its value. It doesn't analyze the value and recursively expand any other variables that may be there.

如果变量在其他变量中定义(我不建议这样做),则是消费者扩展所有变量的工作。

If variables are defined in other variables (something that I wouldn't recommend) is the consumer's job to expand all of them.

一个处理EnvVars的常用C函数(也许这将有所帮助): ExpandEnvironmentStrings

A common C function that deals with EnvVars (maybe this will help): ExpandEnvironmentStrings

这篇关于CMD环境变量未在PATH变量中展开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆