Control return from batch file

I have a batch file that has several commands as follows:

XCOPY DEL RMDIR anotherBatch.bat XCOPY DEL RMDIR 

As you can see, between them there is a call to another batch file (anotherBatch.bat) that performs some other processing.

Now my question is: after anotherBatch is executed, the control will not return to the original batch file, and it ends there.

How can I make sure the control is returned?

+6
source share
2 answers

The SUBROUTINE package is another batch file that is called through the CALL command:

 CALL subroutineName Param1 Param2 

A routine can be placed in the same calling code file. This indicates that a colon is preceded by its name:

 CALL :SubroutineInThisFile Param1 Param2 . . . . . . . . . . . . EXIT /B :SubroutineInThisFile . . . EXIT /B :AnotherSubroutine . . . EXIT /B 

The EXIT / B command (NOT EXIT only) is used to indicate the end of a routine in the same file; this should also be done for the main program.

If another batch file is called without the CALL command, as in your example, then the network result is similar to "GOTO for another file": when the completed file ends, the process ends at this point. I used to call "Overlay" (instead of "subroutine") a batch file called this way.

+13
source

you must explicitly call another batch file

 call anotherBatch.bat 
+7
source

Source: https://habr.com/ru/post/903899/


All Articles