Batch file programming is the
native programming offered by the Microsoft Windows Operating
System. The batch file is created
using any text editors like notepad, WordPad, WinWord or so on, which comprises
of a sequence of built-in commands used to perform some often done tasks like
deleting a series of files of the same type or of different type, creating
logs, clearing unwanted craps from your computer and even for creating a batch
VIRUS.
Whenever a Batch program is
executed, it was interpreted line-by-line by the CLI (Command
Line Interpreter) command.com or
the cmd.exe. The batch file is really helpful in automating tedious tasks and
for maintaining system logs. The commands used while creating a batch file are
case insensitive, in the sense that it may accept both small and upper case
letters.
How to create
a Batch Program:
As said earlier, batch programs
can be written using any of the text editors such as notepad, wordpad and so
on, but notepad is the most often used text editors in such cases. Like any
other programing languages, lets start our first program with the ‘Hello
World’ program.
1. Open up a notepad and type the
following.
@echo off
Echo Hello World
pause
2. Save the file with any name
you wish, but make sure that you save the file extension with .bat, in this
case I am saving this file as ‘file.bat’.
3. When you save the batch file,
then the icon becomes like the left icon,
In Windows XP, the Batch file
icon looks like right, whereas in Windows Vista the Icon looks like the below
image,
4. Just double click to execute
the batch file that you have created now. And the output looks like,
5. Congratulations!
You're well on your way to becoming a Batch programmer.
Let me explain what does the
above given program does,
‘echo’ is the command
used to print text on the screen, so whatever that follows the echo
command will be displayed on the
output screen. This command is just like the ‘printf’ statement
in the C language.
When you type the echo
command alone, then it will tell you whether the ‘echo is ON’ or ‘echo is OFF’.
It’s always recommended to turn
the echo off, else it will display the prompts like (C:\>) and so on. In order
to avoid the prompts being displayed, the echo is turned off by using the
command “@echo off” or simply by using the “echo off”.
“Echo Hello
World” will display the “Hello World” on the output screen, and the
pause command is used to wait for the user interaction, whether to proceed
further or not. If the pause is not used, then the batch will terminate immediately after displaying the “Hello World”.
Have u more Batch Program????
ReplyDelete