the problem/feature of the missing endlocal on syntax errors is known, see Exit from nested batch file
It can be useful to examine all variables when a batch file crashes.
But in your case, you want a clean environment after calling a batch file, even after a syntax error.
I suppose, the only solution is to use a child process for this.
Code: Select all
REM *** Trampoline jump
FOR /F "tokens=3 delims=:" %%L in ("%0") do goto :%%L
REM *** Restart this batch file in a child process
cmd /c "%~d0\:Start:\..\%~pnx0"
echo Show the content of test after a crash
REM *** Force a syntax error