1.使用batch file设置PATH
setx PATH "%cd%;%path%;"
pause
2.用户PATH和系统PATH
Windows实际上是将系统PATH和用户PATH进行合并,使用echo %path%
可查看到合并后的结果。
有时会出现这样的问题,虽然将可执行文件的目录添加到了用户PATH中,可是在CLI中运行时却说找不到命令,这是怎么回事呢?
实际上对系统PATH有字符串长度限制,当系统PATH超过某一长度时,用户PATH将不再合并到系统PATH中,所以找不到命令。
在MSDN上有如下说明:
Found out that on Windows Server 2003, once the system PATH passes 1920 characters, the user PATH environment variable is no longer merged with it to set the process PATH environment variable, even though the full system PATH (even if larger) will be included in the process PATH variable.