returning errorlevel from batch function doesnt work
<p>I have some function in batch script:</p>

<pre><code>:run
set "CMD=%*"
&lt;...&gt;
timeout 300s !CMD!
if %errorlevel% equ 0 (
    echo !CMD! &gt;&gt;  ./!_tool!.OK
) else (
    echo !CMD! &gt;&gt;  ./!_tool!.FAIL
    echo exitcode= %errorlevel% &gt;&gt; ./FAIL
    echo ===STOP=== %date% %time%
    exit /b %errorlevel%
)
exit /b %errorlevel%
</code></pre>

<p>and im checking its %errorlevel% code in the main cycle:</p>

<pre><code>for /f "tokens=*" %%t in (%TEST_LIST%) do (
    &lt;...&gt;
    call :run %TOOL% -O0 -S %REPO_PATH%\%%t
    if %errorlevel% equ 0 (
        echo %%t PASSED
    ) else (
        echo %%t FAILED
    )
</code></pre>

<p>But the issue when <code>timeout 300s !CMD!</code> returns errorlevel 1 and is returning <code>exit /b %errorlevel%</code> as 1 (<code>./!_tool!.FAIL</code> being created and so on) doesnt affect the main cycle's IF and im getting <code>echo %%t PASSED</code> anyway. </p>

<p>Cannot function return code be checked this way or what? </p>

<p>P.S. Some &lt;...> code is working correctly, so I've cut it</p>