How to create a batch file
A batch file is a text file containing a series of commands. If the batch file is run, it reads all the inputs sequentially one by one and provide the outputs. This page will provide you the details idea about batch file and the process of creating batch file.
Extension of batch file name:
Generally each operating system has different extension for batch file. Some of them are mentions below:
- For DOS, the extension is .bat
- For Windows, the extension is .bat
- For Windows NT, the extension is .cmd
- For 4DOS, the extension is .btm
- For Windows 9x, the extension is .bat
Steps fosr creating DOS file:
- After clicking on Start menu, select Run and type notepad. Now you will see a window will be opened. Notepad is used to write the code. You may use any other type of editor also such as wordpad, editplus etc.
- From that window, click on File and you will see a drop down menu will be appeared. Select Save As... form the drop down menu.
- Later, you will write the file name and a .bat extension of that file. For example, if your file name is myFile than the file name will be myFile.bat.
- Type @echo off at the beginning of the file. This line prevents the spaces in the batch file to read during execution time.
- Now write the desired command on each line one by one.
- Save the file and close the file.
- Go to the location where you save the file. Double click on the file (in this case myFile.bat). Now the program will run and from now you don't need to write the command again and again. You just double click on the .bat file and all's are done.
Example of creating batch file:
You want to check your internet connectivity by pinging one ip or address such as yahoo.com. So, your batch file will look like the followings:
ping www.yahoo.com -t
The out put of the program will be like the following: