How to Run Batch (.bat) File in CMD

MD Aminul Islam Feb 02, 2024
  1. Run Batch (.bat) File in CMD by Direct Click
  2. Run Batch (.bat) File in CMD by Providing the Direct Location to the File
  3. Run Batch (.bat) File in CMD Using the Change Directory (CD) Command
How to Run Batch (.bat) File in CMD

This article will show how we can run a Batch file, .bat, using CMD.

There are three ways to run a Batch file. Let’s discuss them in the following sections.

Run Batch (.bat) File in CMD by Direct Click

In this way, you only need to go to your file location and double-click on it. But in this way, the file runs and immediately closes when its task finishes.

So, this way is not preferable if your Batch Script doesn’t show any output at the end.

Run Batch (.bat) File in CMD by Providing the Direct Location to the File

In this way, you need to provide the exact file location of the command. In CMD, type the exact location with filename on double quote like the following.

"G:\YOUR_DIRECTORY\Test_File.bat"

Run Batch (.bat) File in CMD Using the Change Directory (CD) Command

In this way, you have to locate your location using the change directory (cd) command and directly put the name of your file, as shown below.

CD "G:\YOUR_DIRECTORY\"
Test_File.bat

All of the method we discussed above is only for Windows CMD.

MD Aminul Islam avatar MD Aminul Islam avatar

Aminul Is an Expert Technical Writer and Full-Stack Developer. He has hands-on working experience on numerous Developer Platforms and SAAS startups. He is highly skilled in numerous Programming languages and Frameworks. He can write professional technical articles like Reviews, Programming, Documentation, SOP, User manual, Whitepaper, etc.

LinkedIn

Related Article - Batch Script