I have this code: Code: @echo off REM Detect either Windows 32 or 64 bit if /i %PROCESSOR_ARCHITECTURE%==x86 ( if not defined PROCESSOR_ARCHITEW6432 (set xOS=Win32) else (set xOS=Win64) ) else set xOS=Win64 REM Search for Java installation setlocal enabledelayedexpansion if /i %xOS%==win64 ( if exist "%programfiles(x86)%"\Java\jre1.8* ( for /f "delims=" %%j in ('dir /b /ad "%programfiles(x86)%"\Java\jre1.8*') do set javapath=%%j set javapathsec="%programfiles(x86)%"\Java\!javapath!\lib\security ) else ( echo ERROR: Java 8 ^(x86^) not installed echo. pause goto :eof ) ) else ( if exist "%programfiles%"\Java\jre1.8* ( for /f "delims=" %%j in ('dir /b /ad "%programfiles%"\Java\jre1.8*') do set javapath=%%j set javapathsec="%programfiles%"\Java\!javapath!\lib\security ) else ( echo ERROR: Java 8 ^(x86^) not installed echo. pause goto :eof ) ) endlocal echo %javapath% echo %javapathsec% pause But the outcome of this is always "ECHO is off" instead of the actual values of the variables. The variables javapath and javapathsec are not being set! Why isn't setlocal/endlocal working? I want enabledelayedexpansion to be only for this code block
endlocal remove the variable set before it instead use setlocal disabeldelayedexpansion or this one line trick (not verified) Code: endlocal &set javapath=%javapath% &set javapathsec=%javapathsec%
Will using disabledelayedexpansion instead of endlocal have the same effect for the code block? In CMD what's the default behavior? Indeed delayed expansions disabled?