first program.
Read: Introduction to Batch File Programming
How to Create a Batch File
First before writing the program, I’ll give you the basic procedure to create, and run the batch files.
1. Open any text editor you have. A normal notepad that is present in windows is enough. You can open notepad through the run. Just press “win+r” keys on your keyboard, in the run dialog box type “notepad” and press enter. This opens a new notepad.
2. Next write the commands of your batch file.
3. Press “ctrl+s” to save your file. Name your file with an extension as “.bat”, for example, “Hello.bat”. Then select all files and click on save.
4. Then open command prompt (typing “cmd” in run dialog box opens up the command prompt) and type your file name along with the extension to run it. You may also double click on your batch file to run it directly.
Print Hello World Using Batch Commands
Program version #1
echo "Hello World!!!"
This seems very simple. Your first program consists of only a single line. Isn’t it awesome? Yes, it is. This is the beauty of batch files.
The echo is used to display a message that is several lines long you can include several echo commands one after the other in your batch program. This is similar to printf() function in C, we need not use any quotes to specify the message here. Content that immediately follows the echo command is printed.
Syntax of echo Command
echo [{on|off}] [message]
In the above syntax, on|off specifies whether to turn the command-echoing feature on or off. The message specifies the text that you want to print on the screen.
program using echo off.
Program Version #2
@echo off echo "Hello World!!!"
Output
C:Usersuser1Desktop>HelloWorld.bat
“Hello World!!!”
Final Version of Hello World
@echo off echo "Hello World!!!" pause
C:Usersuser1Desktop>HelloWorld.bat
“Hello World!!!”
Press any key to continue . . .
pressing a key.
Try Out yourself
Try out these simple programs and see the outputs on your own.
Program 1
echo off echo. echo formats and checks echo new disks echo This batch program echo.
Program 2
@echo off echo ^<Less than,^> Greater than, ^|or Symbols
By formats and checks, you mean what O.o ?
when going to CMD to execute the batch, users may have to change directories to where they have saved the batch file in order to execute
Thanks a lot! Really helped understand what @echo off is 🙂
Thank u bro