RefreshEnv doesn't always work from inside batch file? #2428
Replies: 2 comments 2 replies
-
I've tried using Also here is an example of my usage - I start with the the 'cs1110' version (3.8 anaconda), then I use the old script to swap to the 3.10 version, and when I check it has updated correctly.
Then I try the script that takes an argument, and I check to see that it has not updated.
But if I manually refresh it is clear that the environment variable did update, but RefreshEnv didn't work for some reason
(edit - formatting again) |
Beta Was this translation helpful? Give feedback.
-
Perhaps it's not refreshing the environment because you first called Try executing endlocal
RefreshEnv.cmd or endlocal
call RefreshEnv.cmd
@rem more commands...
|
Beta Was this translation helpful? Give feedback.
-
I had created some .bat scripts to switch which version of python is on my path (I know there are solutions for this, but I chose to do this in part as an exercise). The issue of course is that when I edit environment variables I need to refresh them so I can use them in the current terminal window. RefreshEnv worked great for this - in my proof of concept script. When I improved my script to automatically detect installed versions of python (so I wouldn't have to hardcode each version) RefreshEnv seems not to work. This is the working proof of concept - it edits the variables, and then refreshes the terminals environment variables.
My improved version takes an argument, checks if there is a folder that matches that argument, and if so sets that folder to be the new python home. It uses the same code to set/refresh, but for some reason it doesn't refresh. It will edit the variables and print out the "Refreshing environment variables from registry" message, but when I check if they updated they aren't. If I run RefreshEnv manually they update, so I know the environment variables were edited, just not refreshed.
(edits - originally I messed up the code formatting)
Beta Was this translation helpful? Give feedback.
All reactions