What commands are available in a batch file?
A batch file is a collection of MS-DOS and Windows command line commands that can be run on a computer. If you are familiar with the command line, you can use your prior knowledge to help you create a batch file. If you're new to the command line or need a refresher, see our how to use the Windows command line (DOS) page.
Below is a listing of commands used in a batch file with additional information about each of the commands.
Tip: Just like all commands, all batch file commands are not case sensitive. However, we listed the batch file commands in all caps to help with identification.
The at symbol does not echo back text after the symbol. The @ is most often used as @ECHO OFF to prevent any of the commands in the batch file from being displayed, just the information outputted by the command.
ECHO Hello %1
With a batch file containing the above line if you type myname (name of bat file) and then your name, as shown below.
It would output "Hello Bob" because "Bob" is the first matched text.
Tip: You can keep going to %2, %3, etc. For example, you could use %2 for a middle name and %3 as the last name.
Two colons in front of any line are one of two ways of adding remarks into the batch file without displaying or executing that line when the batch file is run. Unlike REM, this line is not shown regardless if ECHO off is in the batch file.
By adding a colon in front of a word, such as LABEL, you create a category, more commonly known as a label. A label allows you to skip to certain sections of a batch file such as the end of the batch file. Also see GOTO.
A call is used to run another batch file within a batch file. When the batch file that is called is completed, the remainder of the original batch file is completed. If the batch file does not exist, you get an error.
CHOICE and SET
See our how to use choice and set in a batch file page for an example of how you can create options in your batch file. Further information about each of these commands can also be found on the choice and set page.
Just like the DOS command would clear your screen. We find it helpful to run the cls command at the top of your batch file to clear any previous commands or output and make any output from the batch file easier to find and read.
Echo a message in the batch file. Such as ECHO Hello World prints Hello World on the screen when executed.
Note: Without @ECHO OFF at the beginning of the batch file you'll also get "ECHO Hello World" and "Hello World."
Tip: If you'd just like to create a blank line, type ECHO. adding the period at the end creates an empty line.
Exits out of the DOS window if the batch file is running from Windows. See the exit command page for further information on this command.
Jumps to a label or section of a batch file. The goto can make it easy to jump back to the start or end of a batch file if a condition is met, or an error occurs. See our how to use choice and set in a batch file page for an example of how goto can be used.
Used to check for a certain condition if the condition exists. If that condition exists, it performs that function. See the if command for further information on this command.
Prompt the user to press any key to continue.
One of two ways of adding remarks into the batch file without displaying or executing that line when the batch file is run.
The shift command changes the position of replaceable parameters in a batch program. See the shift page for further information on this command.
Used to open Windows programs. For example, START C:\WINDOW\CALC would run the Windows Calculator. The start command can also be used to start any file Windows recognizes. For example, you could start a movie or audio file in a batch file to start your default player for that file.
Note: In Windows 3.x, you need to utilize the WIN command. For example, WIN C:\Windows\CALC.EXE would run Windows and then Calculator after Windows has finished loading.