Batch File:


What is a Batch File and why we use it?

Batch files contain a sequence of DOS commands to be executed by the command line interpreter which are executed in sequential order from a specified file in place of keystrokes from the keyboard. Batch file is an unformatted text file that contains one or more commands and has a .bat or .cmd file name extension. It is a script file in windows. They are invoked from the command line in DOS by typing the filename, or may appear as commands in other batch files.

We use a Batch file to run a program because, when a batch file is executed, the shell program (usually COMMAND.COM or cmd.exe) reads the file and executes its commands. The sequence of commands contained in the batch file are executed sequentially in order and can be displayed on the screen to obtain the desired output.


How to create a batch file:

A batch file must be saved in plain ASCII text. Use simple text editor to save file. Type the commands of your batch file and save the file with .bat extension. In addition, the copy con command in MSDOS can also be used to create small batch files.

Example of batch file commands to print “Hello World!”

@echo off


java HelloWorld



Executing a Batch file:

A batch file is executed by typing its filename without the extension. To run the batch file HELLO.BAT, type






Advantage of using Batch files:

Using a batch file to execute a program or a task has the following advantages:

·         Batch file speed up your work. By placing a sequence of commands in a batch file you only need to type one command.

·         Desired tasks can be performed by creating commands in the Batch files. You can create batch files to customize the system, backup the system, etc.







Leave Comment