call - Execute Other Batch Files

Maintained on
Table of Contents

As the range of applications for batch files expands, you will often end up with several batch files that perform similar processes, or want to call individual batch files in sequence from a batch file used for scheduled execution.

This page explains the call command, which runs another batch file from a batch file, covering basic usage, how it differs from running a file without call, passing arguments, and calling labels, with sample code.

Basic usage of the call command

To call other batch files from a batch file, use the call command.

The basic usage of the call command is as follows.

call <batch file name> [...parameters]

Specify the batch file name and the parameters to pass to it. The extension (.cmd or .bat) can be omitted, but writing it explicitly avoids running an unintended file when files share the same name.

Using the call command, the specified batch file is executed and returns to the calling batch file after completion.

Without call, control does not return

If you write another batch file name in a batch file without call (for example, just callee.cmd), processing moves to that file and never returns to the caller. Always use call if you want the caller’s remaining commands to run.

Examples of the call command

Executing other batch files

As an example, prepare the caller.cmd to be executed directly and the callee.cmd to be called.

caller.cmd looks like this:

@echo off

echo Started caller.cmd.

call callee.cmd

echo Finished caller.cmd.

Similarly, callee.cmd looks like this:

@echo off

echo Started callee.cmd.

echo Finished callee.cmd.

When caller.cmd is executed with the above settings, the following will be displayed:

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>caller.cmd
Started caller.cmd.
Started callee.cmd.
Finished callee.cmd.
Finished caller.cmd.
C:\users\user>

When caller.cmd is executed, callee.cmd is executed by the call command, and after callee.cmd is completed, it returns to caller.cmd.

In this way, when using the call command, the calling batch file waits until the called batch file is completed.

Executing a batch file by passing arguments

Next, we will explain how to execute a batch file by passing arguments to it.

Prepare caller.cmd to be executed directly and callee.cmd to be called.

caller.cmd looks like this:

@echo off

echo Started caller.cmd.

call callee.cmd 1

call callee.cmd 2

echo Finished caller.cmd.

callee.cmd is written as follows:

@echo off

echo Started callee.cmd.

echo This is execution number %1.

echo Finished callee.cmd.

When caller.cmd is executed with the above settings, the following will be displayed:

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>caller.cmd
Started caller.cmd.
Started callee.cmd.
This is execution number 1.
Finished callee.cmd.
Started callee.cmd.
This is execution number 2.
Finished callee.cmd.
Finished caller.cmd.
C:\users\user>

Receiving the exit code of the called batch file

When the called batch file ends with exit /b <number>, that value is set in ERRORLEVEL. The caller can check it right after call to determine success or failure.

@echo off

call callee.cmd
if errorlevel 1 (
    echo callee.cmd failed.
    exit /b 1
)

echo callee.cmd finished successfully.

For more on exit /b, see the following page.

Calling a label in the same batch file

call can also call a label in the same batch file instead of another file. Prefix the label name with :, and end the subroutine with exit /b to return to the caller.

@echo off

call :greet Taro
call :greet Hanako

exit /b

:greet
echo Hello, %1.
exit /b
- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>sample.cmd
Hello, Taro.
Hello, Hanako.
C:\users\user>

Reliably calling a batch file in the caller’s folder

A relative path such as call callee.cmd is resolved against the current directory. When the batch file is started with “Run as administrator” or from Task Scheduler, the current directory is not necessarily the caller’s folder, so callee.cmd may not be found.

To reliably call a file in the same folder as the caller, use %~dp0, which expands to the folder of the batch file itself. Wrap the whole path in double quotes so it works even if the path contains spaces.

call "%~dp0callee.cmd"

The difference between the current directory and %~dp0 is explained in detail on the following page.

Use exit /b, not exit, in the called file

If a called batch file runs exit without /b, it ends not just the batch file but cmd.exe itself, and control never returns to the caller. To return to the caller, use exit /b (optionally with an exit code, such as exit /b 1).

If you want to achieve parallel processing

There may be cases where you want to execute the next process without waiting for the completion of the called batch file when calling a batch file.

If you use the call command, the next process will be executed after waiting for the completion of the called batch file.

If you want to execute the next process without waiting for completion, use the start command.

For more information on the start command, see the following page.

Summary

  • To run another batch file and return to the caller, use call
  • Pass arguments after the file name, as in call callee.cmd 1, and receive them with %1 in the callee
  • Call a label in the same file with call :label and return with exit /b
  • To run without waiting for completion, use start
  • Call a file in the caller’s folder with call "%~dp0callee.cmd", and end the called file with exit /b

Exercise

Practice Problem

There are two batch files, caller.cmd and callee.cmd. If you execute caller.cmd in this state, which one will be the third to be displayed by the echo command?

caller.cmd
@echo off

echo Started caller.cmd.

call callee.cmd

echo Finished caller.cmd.
callee.cmd
@echo off

echo Started callee.cmd.

echo Finished callee.cmd.

Choose one answer.

  1. Started callee.cmd.
  2. Finished callee.cmd.
  3. Finished caller.cmd.
#Command Prompt #Batch File #call #Argument #Command Line #Command