This doesn’t make sense and I cannot understand why this doesn’t work.
The following batch script works well and prints the following output
ABC
function_result=123
@echo off
setlocal
set "version_1=3.11.5"
if "%version_1%"=="3.11.5" (
echo ABC
)
call :MyFunction
set "function_result=%errorlevel%"
echo function_result=%function_result%
endlocal
exit /b 0
pause
:MyFunction
set "a=123"
exit /b %a%
However, if you move the funtion call (the 3 lines) into the if-clause then the output is
ABC
function_result=
As you can see the function result is nothing.
if "%version_1%"=="3.11.5" (
echo ABC
call :MyFunction
set "function_result=%errorlevel%"
echo function_result=%function_result%
)
Can anyone please help with this, since I need to call the function from within a condition clause?