CMD commands:
setx SOMEVARIABLE "newpath" /M
setx SOMEVARIABLE "%SOMEVARIABLE%;newpath2" /M
Expected output on ECHO %SOMEVARIABLE%
:
newpath;newpath2
Actual output:
%SOMEVARIABLE%
Actual value stored (From System Properties->Environment Variables GUI):
%SOMEVARIABLE%;newpath2
The only way i can get the expected output is, if i restart the command prompt every time i modify the environment variable.
I'm using this command to automate environment variable value appending multiple times during the same process.
- Why doesn't environment variable get updated in cmd without restart?
- Is it possible to get the updated value of %SOMEVARIABLE% without
restarting the command prompt?
Best Answer
The problem is that
setx
modifies the global environment, not the local environment. Therefore, you have to restart the command prompt to pick up the change.You have two options:
Create a batch-file that does both and use that: