当通过上下文菜单运行cmd时,PATH变量不同

编程入门 行业动态 更新时间:2024-10-27 10:33:54
本文介绍了当通过上下文菜单运行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变量不同

本文发布于:2023-11-23 02:21:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619732.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上下文   变量   菜单   cmd   PATH

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!