%PATH% on Windows 2008 Server actually not working

这一生的挚爱 提交于 2020-01-05 03:32:50

问题


As you can see below, %AppData%\npm is added in the system Path variable. I've also tried adding it to the User Path variable. The file grunt.cmd exists in the directory, but only works if I specify it with an absolute path. AKA, path does not work.

C:\Users\TeamCity>echo %path%
%AppData%\npm;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows
\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\Microsoft SQL Server\10
0\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program F
iles\Microsoft SQL Server\100\DTS\Binn\;c:\Program Files (x86)\Microsoft SQL Ser
ver\100\Tools\Binn\VSShell\Common7\IDE\;c:\Program Files (x86)\Microsoft SQL Ser
ver\100\DTS\Binn\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program
Files\nodejs\

C:\Users\TeamCity>dir %appdata%\npm
 Volume in drive C has no label.
 Volume Serial Number is B845-1135

 Directory of C:\Users\TeamCity\AppData\Roaming\npm

05/29/2013  03:14 AM    <DIR>          .
05/29/2013  03:14 AM    <DIR>          ..
05/29/2013  03:14 AM               298 grunt
05/29/2013  03:14 AM               159 grunt.cmd
05/29/2013  03:13 AM    <DIR>          node_modules
               2 File(s)            457 bytes
               3 Dir(s)  23,690,498,048 bytes free

C:\Users\TeamCity>grunt
'grunt' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\TeamCity>%appdata%\npm\grunt
grunt-cli: The grunt command line interface. (v0.1.9)

Running on:

  • Windows Server 2008 R2 Datacenter
  • Service Pack 1
  • 64-bit

回答1:


I don't think you can defer variable expansion in the path. What's in the path is used as is, it doesn't get re-interpreted during a search.

In fact, you must have worked really hard to get that in as %AppData% since you would need to do something like:

path=^%AppData^%\npm;%path%

If you were to just use:

path=%AppData%\npm;%path%

you'd find the actual path would be substituted, so that the path becomes:

C:\Users\TeamCity\AppData\Roaming\npm;C:\Windows\system32; ...



回答2:


Interestingly enough, a last-ditch effort of "turning it off and on again" actually worked. Alternatively, you can copy the whole path after you added it and type in cmd:

> SET PATH=

and paste your path.



来源:https://stackoverflow.com/questions/16805023/path-on-windows-2008-server-actually-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!