call - Execute Other Batch Files

Maintained on

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>
おすすめ書籍※ 広告を含む場合があります
中小企業経営者のためのRPA入門 RPA導入を成功させる方法

中小企業経営者のためのRPA入門 RPA導入を成功させる方法

60分でわかる! AIエージェント 超入門

60分でわかる! AIエージェント 超入門

コマンドラインの黒い画面が怖いんです。

コマンドラインの黒い画面が怖いんです。

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門

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>

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

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.
回答がサーバーに送信されることはありません
#Command Prompt #Batch File #call #Argument #Command Line #Command