I have a batch file which has several commands as follows;
XCOPY
DEL
RMDIR
anotherBatch.bat
XCOPY
DEL
RMDIR
As you can see, in between there is a call to another batch file (anotherBatch.bat), which does some other processing.
Now my question is after anotherBatch gets executed, the control never returns back to the original batch file and it just ends there.
How do I make sure that the control is returned back ?
A Batch SUBROUTINE is another Batch file called via CALL command:
CALL subroutineName Param1 Param2
The subroutine may be placed in the same file of the calling code. This is indicated by preceding its name with colon:
CALL :SubroutineInThisFile Param1 Param2
. . . .
. . . .
. . . .
EXIT /B
:SubroutineInThisFile
. . .
EXIT /B
:AnotherSubroutine
. . .
EXIT /B
The EXIT /B command (NOT just EXIT) is used to mark the subroutine end in the same file; this must also be done for the main program.
If another Batch file is invoked with no CALL command, as in your example, the net result is similar to a "GOTO to another file": when the invoked file ends, the process ends at that point. I used to call "Overlay" (instead of "subroutine") a Batch file called this way.
you should explicitly call the other batch file
call anotherBatch.bat
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With