Name
call
Synopsis
Invoke a batch file from within another batch file, returning control to the original when the called file completes.
Syntax
call [filename] [arguments]
Description
The call command lets you invoke a batch file from
within another batch file and wait for it to finish before
continuing. Once the called file has completed its execution, the
control returns to the original batch file.
Warning
If you run another batch file from within a batch file without using
call, the control will never be returned to the
parent batch file when the child process is finished. The whole thing
just quits. Of course, this fact can be put to use; for example, it
helps to avoid recursion when a batch file calls itself.
The options for call are as follows:
-
filename Specifies the filename of the batch file to call.
-
arguments Specifies any command-line arguments to be passed to the target batch file.
Examples
The following parent.bat calls
child.bat, and then returns the control back to
itself:
parent.bat:
@echo off cls call child.bat First set first=%inputvar% call child.bat Second set second=%inputvar% echo You typed %first% and then you typed %second%
child.bat:
set /p inputvar=Please type the %1 option: echo Thank you.
In this example, parent.bat launches
child.bat twice, which illustrates how you can
write modular code in batch files. Child.bat
asks for input and then places what the user types into the
environment variable inputvar. When control is
returned to parent.bat, the variable ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access