Return control from a batch file
Asked Answered
M

2

7

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 ?

Manhattan answered 16/12, 2011 at 9:17 Comment(0)
G
15

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.

Girth answered 16/12, 2011 at 11:0 Comment(1)
Thx a lot...Is there any variation to CALL like params to make anotherBatch open in a new window AND also close automatically when done...Manhattan
G
7

you should explicitly call the other batch file

call anotherBatch.bat
Glimmer answered 16/12, 2011 at 9:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.