I have a batch script that is just toggles my python pathing. When I run it a second time, my variable doesn't get set but the string I want it to be set to is echoed onto the console.
First time running the script:
C:\Users\Hai\Desktop>FOR /F "delims=" %I IN ('Python -V') DO (
setlocal
set "ver=%I"
)
C:\Users\Hai\Desktop>(
setlocal
set "ver=Python 3.6.3"
)
Second time running same batch file without closing console:
C:\Users\Hai\Desktop> chPythonVer.bat
C:\Users\Hai\Desktop>FOR /F "delims=" %I IN ('Python -V') DO (
setlocal
set "ver=%I"
)
Python 2.7.15
This is how I'm setting my variable:
FOR /F "delims=" %%I IN ('Python -V') DO (
setlocal
set "ver=%%I"
)
echo the current version pathed is %ver%
SET /P c=would you like to switch to the other version? [y/n]
IF /I "%c%" EQU "y" (
IF "%ver%" EQU "Python 3.6.3" (
endlocal
set PATH= ...
echo switched to Python 2.7.15
pause
) ELSE (
endlocal
set PATH= ...
echo switched to Python 3.6.3
pause
)
) ELSE IF /I "%c%" EQU "n" (
endlocal
pause
)