This is very funny (and strange)! Each execution of "(goto)" (the "echo on &" part is not necessary),
cancel the execution of the last called subroutine!
Check this:
FirstOne.batCode: Select all
@echo off
setlocal
set var=First One
echo FirstOne.bat, calling Second.bat:
call Second.bat
echo Returned to FirstOne.bat, var = %var%
Second.batCode: Select all
@echo off
setlocal
set var=Second
echo Second.bat, calling TheThird.bat:
call TheThird.bat
echo Returned to Second.bat, var = %var%
TheThird.batCode: Select all
@echo off
setlocal
set var=The Third
echo TheThird.bat, calling XYZ.bat:
call XYZ.bat
echo Returned to TheThird.bat, var = %var%
XYZ.batCode: Select all
@echo off
setlocal
set var=XYZ
echo XYZ.bat, calling CancelPreviousCalls.bat:
call CancelPreviousCalls.bat
echo Returned to XYZ.bat, var = %var%
CancelPreviousCalls.batCode: Select all
@echo off
setlocal
set var=Cancel Previous Calls
echo ---------------------------
echo I am CancelPreviousCalls.bat
for /L %%i in (1,1,%CANCEL%) do (
call echo Cancel %%i- "%%~NX0", var = %%var%%
(goto) 2> NUL
)
echo Ending CancelPreviousCalls.bat
echo -----------------------------
This is the output of a test:
Code: Select all
C:\ set CANCEL=0
C:\ FirstOne.bat
FirstOne.bat, calling Second.bat:
Second.bat, calling TheThird.bat:
TheThird.bat, calling XYZ.bat:
XYZ.bat, calling CancelPreviousCalls.bat:
---------------------------
I am CancelPreviousCalls.bat
Ending CancelPreviousCalls.bat
-----------------------------
Returned to XYZ.bat, var = XYZ
Returned to TheThird.bat, var = The Third
Returned to Second.bat, var = Second
Returned to FirstOne.bat, var = First One
C:\ set CANCEL=2
C:\ FirstOne.bat
FirstOne.bat, calling Second.bat:
Second.bat, calling TheThird.bat:
TheThird.bat, calling XYZ.bat:
XYZ.bat, calling CancelPreviousCalls.bat:
---------------------------
I am CancelPreviousCalls.bat
Cancel 1- "CancelPreviousCalls.bat", var = Cancel Previous Calls
Cancel 2- "XYZ.bat", var = XYZ
Returned to TheThird.bat, var = The Third
Returned to Second.bat, var = Second
Returned to FirstOne.bat, var = First One
C:\ set CANCEL=4
C:\ FirstOne.bat
FirstOne.bat, calling Second.bat:
Second.bat, calling TheThird.bat:
TheThird.bat, calling XYZ.bat:
XYZ.bat, calling CancelPreviousCalls.bat:
---------------------------
I am CancelPreviousCalls.bat
Cancel 1- "CancelPreviousCalls.bat", var = Cancel Previous Calls
Cancel 2- "XYZ.bat", var = XYZ
Cancel 3- "TheThird.bat", var = The Third
Cancel 4- "Second.bat", var = Second
Returned to FirstOne.bat, var = First One
Antonio