Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return control from a batch file

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 ?

like image 567
copenndthagen Avatar asked Dec 16 '11 09:12

copenndthagen


2 Answers

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.

like image 86
Aacini Avatar answered Sep 20 '22 18:09

Aacini


you should explicitly call the other batch file

call anotherBatch.bat
like image 40
MLN Avatar answered Sep 16 '22 18:09

MLN