Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PATH variable different when cmd was run through the context menu

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...

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.

enter image description here

My question: Why is this happening, what can I do about it?

like image 493
Forivin Avatar asked Apr 26 '15 13:04

Forivin


People also ask

Can you have 2 PATH variables?

To add multiple path values under the PATH variable separate your values with a semi-colon. To be clear, this is only true for certain variables. For instance adding another path to the TEMP variable would just break things.

What is stored in the $PATH variable?

The PATH variable is an environment variable containing an ordered list of paths that Linux will search for executables when running a command. Using these paths means that we don't have to specify an absolute path when running a command.

Does order matter in PATH variable?

I've seen numerous articles (see 1 2 3) addressing if order matters with regards to entries in the PATH environment variable and it is clear that the answer is a resounding yes.


1 Answers

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.

So the solution would be to simply restart explorer.exe.

like image 155
Forivin Avatar answered Sep 26 '22 01:09

Forivin