当通过上下文菜单运行cmd时,PATH变量不同 [英] PATH variable different when cmd was run through the context menu

查看:347
本文介绍了当通过上下文菜单运行cmd时,PATH变量不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是花了最后一个小时,试图找出为什么地狱我的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变量不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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