我只是花了最后一个小时,试图找出为什么地狱我的PATH变量没有更新我的cmd.exe。 现在我发现它有点更新,但是只在某些条件... 我更新了通过 Win + Break - >更改设置 - >高级 - >环境变量...
I just spent the last hour on trying to find out why the hell my PATH variable wasn't updating for my cmd.exe. Now I figured out that it kind of did update, but only for certain conditions... I updated it via Win+Break -> Change Settings -> Advanced -> Environment Variables...
现在当我通过 Win + R - cmd - >输入 PATH变量显示我设置它的任何内容。 但是当我通过 Shift + Rightclick打开一个新命令行到文件夹 - >在此处打开命令窗口,PATH变量显示过时的内容。
Now when I open a new commandline via Win+R -> cmd -> Enter the PATH variable shows whatever I set it to. But when I open a new commandline via Shift+Rightclick into folder -> Open command window here, the PATH variable shows outdated content.
>
我的问题:为什么会发生这种情况,我能做些什么呢?
My question: Why is this happening, what can I do about it?
推荐答案正如Hans Passant指出的,问题是通过浏览器的上下文菜单运行cmd会将cmd作为子进程导入浏览器,导致它从explorer.exe继承环境变量,而不是自己获取它们。因为一个进程通常只在开始时加载环境变量一次,并且不监听更改,所以explorer会将过期的变量继承到cmd实例。
As pointed out by Hans Passant, the problem was that running cmd via the explorer's context menu spawns cmd as a child process to the explorer causing it to inherit the environment variables from explorer.exe instead of acquiring them itself. And since a process usually only loads the environment variables once in the beginning and doesn't listen for changes, the explorer inherited outdated variables to the cmd instance.
所以解决方案是简单地重新启动explorer.exe。
So the solution would be to simply restart explorer.exe.
更多推荐
当通过上下文菜单运行cmd时,PATH变量不同
发布评论