Hi Jesus2099,
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
@echo off
REM *** Trampoline jump
FOR /F "tokens=3 delims=:" %%L in ("%0") do goto :%%L
set test=original
REM *** Restart this batch file in a child process
cmd /c "%~d0\:Start:\..\%~pnx0"
echo Show the content of test after a crash
set "test"
exit /b
:start
setlocal
set TEST=Content
REM *** Force a syntax error
()