Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk5 min

How Do I Call a Batch File from Within Another Batch File?

The correct way to run a child batch file and continue the parent script is to use call, with quoted paths, explicit exit codes, and %~dp0 for reliable relative paths.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use call when one Windows .bat or .cmd file must run another and the parent script must continue afterward:

call child.bat

For a script stored beside the parent, the more reliable form is:

As an Amazon Associate I earn from qualifying purchases.

call "%~dp0child.bat"

call creates a nested batch-file context, waits for the child to finish, and returns control to the next command in the parent. See Microsoft’s call documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A complete parent-and-child example

Create parent.bat:

@echo off

call "%~dp0child.bat" "Hello from the parent"
set "rc=%errorlevel%"

if not "%rc%"=="0" (
    echo Child script failed with exit code %rc%.
    exit /b %rc%
)

echo Child script completed successfully.

Create child.bat in the same directory:

@echo off

echo Child received: %~1

exit /b 0

The child prints its argument, returns status code 0, and the parent then continues with its success message.

#1 Best Overall
Sale
Redragon Mechanical Gaming Keyboard Wired, 11 Programmable Backlit Modes, Hot-Swappable Red Switch, Anti-Ghosting, Double-Shot PBT Keycaps, Light Up Keyboard for PC Mac
  • Brilliant Color Illumination- With 11 unique backlights, choose the perfect ambiance for any mood. Adjust light speed and brightness among 5 levels for a comfortable environment, day or night. The double injection ABS keycaps ensure clear backlight and precise typing. From late-night tasks to immersive gaming, our mechanical keyboard enhances every experience
  • Support Macro Editing: The K671 Mechanical Gaming Keyboard can be macro editing, you can remap the keys function, set shortcuts, or combine multiple key functions in one key to get more efficient work and gaming. The LED Backlit Effects also can be adjusted by the software(note: the color can not be changed)
  • Hot-swappable Linear Red Switch- Our K671 gaming keyboard features red switch, which requires less force to press down and the keys feel smoother and easier to use. It's best for rpgs and mmo, imo games. You will get 4 spare switches and two red keycaps to exchange the key switch when it does not work.
  • Full keys Anti-ghosting- All keys can work simultaneously, easily complete any combining functions without conflicting keys. 12 multimedia key shortcuts allow you to quickly access to calculator/media/volume control/email
  • Professional After-Sales Service- We provide every Redragon customer with 24-Month Warranty , Please feel free to contact us when you meet any problem. We will spare no effort to provide the best service to every customer

Basic syntax

call [drive:][path]filename [arguments]

The target should be a batch file with a .bat or .cmd extension:

call child.bat
call child.cmd
call "C:Program FilesMy Scriptschild.bat"
call "%~dp0child.bat" one two
call "%~dp0child.bat" "value containing spaces"

Why not simply write the child filename?

This can transfer batch processing to the other file instead of giving the parent a normal return point:

child.bat
echo This may not run as expected

Use call when the parent must resume:

call child.bat
echo This runs after child.bat returns

The child returns when it reaches the end of its batch context or uses exit /b.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Pass arguments to the child

Parent:

call "%~dp0child.bat" Alice 25 "New York"

Child:

@echo off
echo Name: %~1
echo Age: %~2
echo City: %~3

Output:

Name: Alice
Age: 25
City: New York

Common batch parameters include:

  • %0: the name used to invoke the script
  • %1 through %9: positional arguments
  • %*: all arguments
  • %~1: the first argument without surrounding quotes
  • %~f1: the fully qualified path of the first argument
  • %~dp1: the drive and path of the first argument

These parameter modifiers are documented in Microsoft’s batch parameter reference.

Rank #2
RisoPhy Mechanical Gaming Keyboard, RGB 104 Keys Ultra-Slim LED Backlit USB Wired Keyboard with Blue Switch, Durable Abs Keycaps/Anti-Ghosting/Spill-Resistant Computer Keyboard for PC Mac Xbox Gamer
  • 【Mechanical Keyboard: Responsive BLue Switches】RisoPhy PC keyboard features clicky keys which offer you higher accuracy and quicker response with an enjoyable click sound when typing.This keyboard is more comfortable to type on since it features deeper key travel,greater feedback,and more space between keys.For those who prefer keyboards with a more tactile and "clicky" feel,our keyboard with BLUE switches is a nice choice.
  • 【Rainbow Backlit Keyboard: illuminate Your Desktop】With 9 different backlights,5 levels of light speed and brightness,this computer keyboard enriches your gaming experience and improves your mood greatly,which is a great addition to your desktop,especially in the dark.Plus,the ultra-durable double injection ABS engineered keycaps provide crystal clear uniform backlight and greatly improve your typing accuracy at night.
  • 【High-end 104 Keys Full-Size Keyboard】The Win lock function frees your worry about mistyping when gaming(Fn+Win).Keycaps are pluggable and easy to clean,saving you much unnecessary trouble.We designed 4 hydrophobic holes for this keyboard,allowing water to flow away quickly to prevent damage to the keyboard.No longer afraid of accidents.(✦Include a keycaps puller for cleaning or other needs.)
  • 【Advanced Ergonomic Comfort】This PC gamer Keyboard adopts a scientific stair-up keycap design that keeps your arms in the most natural state to minimize hand fatigue for long time use.In order to improve your posture and make you more comfortable during use,the wired keyboard comes with 2 strong foldable rear kickstands to slope it.Moreover,the keyboard is non-slip enough because there are 4 rubber padding underneath the keyboard.
  • 【100% Anti-Ghosting & 12 Multimedia Combinations】100% anti-ghosting gaming keyboard allows all keys to work simultaneously,no matter how fast you type.12 multimedia key shortcuts allow you to quickly access to calculator/media/volume control/email.RisoPhy mechanical gaming keyboard with the number pad greatly improves your productivity.This ultra-durable keyboard with up to 50 million keystrokes life works well with Windows 7/8/10/XP/VISTA/95/98/XP/2000/ME/VISTA and Mac OS Xbox etc.

Call a script in the parent’s directory

%~dp0 expands to the drive and path portion of the current batch parameter—normally the parent script’s location. It avoids depending on the current working directory, which may differ when the script is started by Task Scheduler, an IDE, or another program.

call "%~dp0libbackup.cmd"

For this layout:

project
  parent.bat
  lib
    backup.cmd

call backup.cmd searches relative to the current working directory. call "%~dp0libbackup.cmd" locates the file relative to parent.bat.

Quote paths containing spaces

Quote both the batch-file path and arguments containing spaces:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
call "C:My Scriptschild.bat" "C:Input Filesdata.txt"

Inside the child, a safe assignment is:

set "input=%~1"
type "%input%"

Quoting handles ordinary spaces, but cmd.exe also gives special meaning to characters such as &, <, >, |, ^, parentheses, and !. Arbitrary strings may require additional escaping. See Microsoft’s cmd.exe syntax documentation.

Rank #3
Sale
Redragon K521 Upgrade Rainbow LED Gaming Keyboard, 104 Keys Wired Mechanical Feeling Keyboard with Multimedia Keys, One-Touch Backlit, Anti-Ghosting, Compatible with PC, Mac, PS4/5, Xbox
  • 【Dreamy Rainbow Gaming Keyboard】K521 Gaming Keyboard Adopts a Different LED Backlight Design, Upgraded on the Traditional LED Backlight Effect, Making the Light More Penetrating, Giving You a More Dazzling Visual Effect, Making Your Gaming Process More Enjoyable
  • 【One Touch Opens & Visual Feast】The K521 Red Dragon Keyboard has a One-Touch on/off Lighting Button for Added Convenience. It also has a Three-Position Adjustable Breathing Mode and a Four-Position Adjustable Brightness Lighting Mode
  • 【Mechanical Feeling & Fast Tapping】The PC Keyboard Keys are Designed for Mechanical Feeling, Giving You a Better Feel During Use and the Ability to Trigger Keys Quickly, Allowing You to Win All Your Games
  • 【19 Keys Anti-Ghosting Keyboard】Anti-Ghosting Ensures Every Button Can Be Triggered. This Allows You to Trigger Key Combinations In The Game Accurately, And Each Skill Can Be Accurately Released to Increase Your Winning Rate. Redragon K521 Will Be Your Perfect Partner
  • 【12 Multimedia Combination Keys】The K521 Wired Gaming Keyboard is Equipped with 12 Multimedia Keys That Can Greatly Enhance Your Gaming/Office Efficiency and Make It More Convenient to Use

Return success or failure

Have the child return an explicit code:

@echo off

if not exist "%~1" (
    echo Input file not found: %~1
    exit /b 2
)

echo Processing "%~1"
exit /b 0

Capture the result immediately after call:

@echo off

call "%~dp0child.bat" "C:datainput.txt"
set "rc=%errorlevel%"

if not "%rc%"=="0" (
    echo Child failed with code %rc%.
    exit /b %rc%
)

echo Child succeeded.

exit /b N exits only the current batch script and sets ERRORLEVEL. Microsoft documents this in the exit command reference.

For threshold-based checks:

if errorlevel 1 echo The child reported an error.

if errorlevel 1 is true for 1 or any greater value; it is not an exact equality test. For exact comparisons, capture the value and compare it as a string:

if "%rc%"=="2" echo The input file was missing.

Call a label in the same batch file

call can invoke a subroutine label in the current file:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
@echo off

call :sayHello Alice
echo Back in the main script.
exit /b 0

:sayHello
echo Hello, %~1
exit /b 0

Use exit /b or goto :eof at the end of the subroutine so execution does not fall through into later code:

Rank #4
Sale
Logitech G413 SE Full-Size Mechanical Gaming Keyboard - Black
  • Take your gaming skills to the next level: The Logitech G413 SE is a full-size keyboard with gaming-first features and the durability and performance necessary to compete
  • PBT keycaps: Heat- and wear-resistant, this computer gaming keyboard features the most durable material used in keycap design
  • Tactile mechanical switches: Uncompromising performance is always within reach with this wired gaming keyboard
  • Premium color, material and finish: Elevate your gaming setup with this backlit keyboard featuring a sleek, black-brushed aluminum top case and white LED lighting
  • 6-Key rollover anti-ghosting performance: Experience reliable key input with this anti-ghosting keyboard versus non-gaming mechanical keyboards
call :deploy
exit /b

:deploy
echo Deploying...
goto :eof

call :label is different from calling a label in another file. For a separate file, call the file itself. Label targets require command extensions; Microsoft documents both forms on the call page and documents goto :eof here.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

call vs. cmd /c vs. start /wait

Method Returns to parent? Separate process? Best use
call child.bat Yes No separate application process; a nested batch context Normal synchronous batch-to-batch calls
call :label Yes No Same-file subroutines
cmd /c ... The new cmd.exe exits Yes, a new command interpreter Deliberate command-shell isolation
start /wait ... After the started process finishes Yes Applications or separate processes

cmd /c is usually unnecessary for an ordinary batch-to-batch call and adds another parsing layer:

cmd /c call "%~dp0child.bat"

Use start /wait mainly for programs such as executables:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
start "" /wait "C:Toolsworker.exe"

The empty quoted argument supplies the window title because start treats its first quoted argument specially. Its waiting behavior is documented in Microsoft’s start reference. Neither command is the normal replacement for call.

Best Value
Sale
AULA F2088 Typewriter Style Mechanical Gaming Keyboard Wired, 104 Keys
  • Retro Typewriter Style Round Keycaps: Mechanical blue switch offers a quicker and springier response, crisp click sound, precise tactile feedback for ultimate gaming performance. Double-shot injection molded vintage steampunk round keycaps for clear backlight and extreme durability. The stepped floating keycap fit your fingertips perfectly for precise positioning, prevent fatigue and wrong typing. Comes with keycap puller for easy keycaps cleaning
  • Multimedia and Backlight Control Knob: This wired mechanical keyboard effortlessly controls media thanks to its dedicated media control keys. Quick-access buttons for media volume, backlight effect, music play, pause, switch. You can switch 19 different lighting effects or adjust the backlit brightness and speed. And you can create 3 customized backlight as you like. Long press knob for three seconds to switch between media and lighting modes
  • Metal Panel and Magnetic Wrist Rest: The computer keyboard panel is made of top-grade aluminium alloy material, with matte-finish texture, sturdy and robust enough to protect it from scratch. The ergonomic ABS palm rest provides firm support that alleviates pressure on your wrist from gaming at an elevated angle. The surface has a smooth and comfortable touch that enhances the feeling of the keyboard. USB connector for a reliable connection and ultimate gaming performance
  • 104 Keys Anti-Ghosting Programmable: This mechanical gaming keyboard features Anti Ghosting Technology which ensures your simultaneous keystrokes register the way you intended, allow multi-keys to work simultaneously with high speed. Each key is controlled by independent switch, let you enjoy high-grade games with fast response, boosting your performance! The PC Gaming Keyboard has been ergonomically designed to be a superb typing tool for office work as well
  • Stylish Durable and Wide Compatibility: Modern and sleek design with superior performance. High low key layout with suspended round key fits fingers effectively, help reduce hand fatigue, aluminum alloy metal panel, matte texture, sturdy and robust, protect it from scratch. Support PC Mac Laptop, Tablet, Desktop computer, suitable for Windows 7/8/10/XP/Vista, Linux and Mac OS systems. USB wired conection, plug and play! No drivers or softwares are required

Important edge cases

Prevent environment changes from leaking back

A called child normally shares the caller’s command environment. Its set, cd, and path commands can affect later parent commands. Use setlocal when those changes should be temporary:

@echo off
setlocal

set "TEMP_SETTING=value"
cd /d "C:Temporary Directory"

rem Work performed with local settings.

endlocal
exit /b 0

setlocal protects the parent environment, but variables created inside the localized scope do not remain available afterward unless you return them through a file, status code, or another mechanism. See Microsoft’s setlocal documentation.

Be careful with pipes and redirection

Microsoft cautions against using pipes or redirection symbols directly with call. Avoid constructions involving |, <, and > unless you understand their cmd.exe parsing behavior and have tested the quoting.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Avoid accidental recursion

@echo off
call "%~f0"

This calls the current file again indefinitely unless an explicit termination condition is provided. Circular calls between multiple batch files can cause the same problem.

Delayed expansion

Variables inside parenthesized blocks may require delayed expansion:

setlocal EnableDelayedExpansion
set "value=before"

(
    set "value=after"
    echo !value!
)

endlocal

setlocal enabledelayedexpansion enables !variable! expansion until the matching endlocal or the end of the batch file. Be especially cautious with exclamation marks in input values.

Troubleshooting checklist

  • Parent does not resume: replace a bare child.bat invocation with call child.bat.
  • File is not found: use call "%~dp0child.bat" and verify the filename and extension.
  • Spaces break the command: quote the target path and each affected argument.
  • Exit code is wrong: capture %errorlevel% immediately after call; ensure the child uses exit /b.
  • Exact status check fails: remember that if errorlevel N means N or greater.
  • Label cannot be found: check spelling, command extensions, and whether the label is actually in the current file.
  • Parent directory changes unexpectedly: add setlocal to the child.

Quick reference

call "%~dp0child.bat" "argument"
set "rc=%errorlevel%"
if not "%rc%"=="0" exit /b %rc%

This guidance applies to Windows cmd.exe batch files, including .bat and .cmd. It is not Bash, PowerShell, or Unix-shell syntax. Microsoft lists these commands for current Windows and Windows Server documentation, including Windows 10, Windows 11, and Windows Server releases.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.