When refreshenv is executed as part of the batch script it exits the script, so no further commands are executed.
I expect batch script to continue after running refreshenv
Here is my batch script:
@rem Install Python
choco install -y python3 --version 3.5.4
refreshenv
python --version
@rem further steps like python modules installation
@rem ...
Output from running the script:
C:\>install-python.bat
C:\>choco install -y python3 --version 3.5.4
Chocolatey v0.10.8
Installing the following packages:
python3
By installing you accept licenses for the packages.
Progress: Downloading chocolatey-core.extension 1.3.3... 100%
Progress: Downloading python3 3.5.4... 100%
chocolatey-core.extension v1.3.3 [Approved]
chocolatey-core.extension package files install completed. Performing other installation steps.
Installed/updated chocolatey-core extensions.
The install of chocolatey-core.extension was successful.
Software installed to 'C:\ProgramData\chocolatey\extensions\chocolatey-core'
python3 v3.5.4 [Approved]
python3 package files install completed. Performing other installation steps.
Installing 64-bit python3...
python3 has been installed.
Installed to: 'C:\Python35'
python3 can be automatically uninstalled.
Environment Vars (like PATH) have changed. Close/reopen your shell to
see the changes (or in powershell/cmd.exe just type `refreshenv`).
The install of python3 was successful.
Software installed as 'exe', install location is likely default.
Chocolatey installed 2/2 packages.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
C:\>refreshenv
Refreshing environment variables from registry for cmd.exe. Please wait...Finished..
So nothing after refreshenv is executed
I test this in the Windows container, but I think it will be the same on any fresh Windows 10 machine:
docker run -it --rm microsoft/windowsservercore:10.0.14393.1884 cmd
(at the moment of writing this is the latest image, but the same problem was seen in older versions)
You need to use call:
call RefreshEnv.cmd
Fantastic! Problem sorted out. Many thanks for the help.
Probably this message printed by choco install can be updated to mention call?
Environment Vars (like PATH) have changed. Close/reopen your shell to
see the changes (or in powershell/cmd.exe just type `refreshenv`).
That message is for non-automated scenarios and your use of refreshenv is in a batch script where it is typical you would use call in front of all of those commands.
If you were using refreshenv in PowerShell then you would need to have the profile installed and could call it as well (refreshenv is an alias for Update-SessionEnvironment in PowerShell).
We could add this to scripting docs - add a comment to #1303.
Hello,
I have a similar problem with choco install nvm and Travis.
nvm is installed but when I run "nvm -v" I have an output:
"The command "nvm -v" failed and exited with 127 during ."
I run the also cmd.exe /c "call RefreshEnv.cmd" before
To Sum up:
choco install nvm
cmd.exe /c "call RefreshEnv.cmd"
nvm -v
Any idea ?
@gsfakianakis , you are executing RefreshEnv.cmd within a separate cmd process which exits, and when you run nmv -v - it runs in the main cmd process, not in the one with refreshed env.
How about just:
choco install nvm
call RefreshEnv.cmd
nvm -v
If you shell is PowerShell, not cmd, try as & RefreshEnv.cmd
I haven't tested, as I don't use Windows anymore, but you got the idea.
Still same issue.
Most helpful comment
You need to use call:
call RefreshEnv.cmd