How To Write A Batch (.bat) File

A batch file contains a series of DOS commands and is commonly used to automate frequently performed various tasks. It makes the life as just save your commands in one file and double click on it from your Windows machine.

  1. Create a .bat file                                                                                                                Create a .txt document file in your Windows desktop. Open the file and save as test.bat(without quotes), you can see the icon changed from .txt to something else.
  2. Add some code to execute
    Learn some simple command to execute
    ECHO – Just do the same as print function
    PAUSE – This outputs the “press any key to continue”, it’s better you add this line after an execution, otherwise, everything will execute so fast and closes the window, so you don’t know what’s happening. This will ask your input before closing the window.                                           Next, open your test.bat and add below lines to it
    ECHO “hello man”
  3.  Run your .bat file                                                                                                                                                                                                        Just double click on your .bat file, it will pop up the windows cmd.exe and display all the outputs.

How To Write A Batch

Editorial Staff

Editorial Staff at tutsplanet is a dedicated team to write various tutorial articles.