Batch files are the collection of command line instruction that are "batched" together in one file. so they can be run to completion without manual intervention of user. Most of command can be executed in command prompt. Batch file can be created using notepad that makes work much easier than command prompt.
Batch file is saved with extension "filename.bat".
Simple Batch Programming to show Hello message is :
Step 1. Open Notepad
Step 2. Copy below code and paste into notepad.
@echo off
echo "hello world"
@pause
echo "hello world"
@pause
Step 3. Now click on File-> mneu then click on Save as->. Give the file name like, with extension "file.bat" then save on desktop.
When you save the batch file, then the icon becomes like the below icon,
Step 4. Now run batch file from your desktop.
Output:
Let me explain what does the above given program does
'echo' is the command used to print text on the scree. This command is just like the 'printf' statement in the C. There is two status of 'echo' command echo is ON or echo is OFF. It is always recommended to turn the echo off, else it will display the prompts like (C:\>) and so on. You can use echo off t or @echo off to avoid the prompts being display.
'Pause' command is used to wait for the user interaction, whether to proceed further or not. If the pause is not used then batch will terminate immediately after displaying the output.
Furher Reading:-
Modes of Batch Programming
There are two different modes that are supported by DOS (Disk Operating System), they are,
1. Interactive Mode.
2. Batch Mode (Silent Mode).
Interactive mode:
In interactive mode, it includes the user interaction while processing. When a command is executed, it interact with user for input and depending on the input entered by the user, the further process is carried out.
For example, let's use the 'del' command
The 'del' command is used for deleting files that resides inside a directory. Now I am going to delete all the folders insides a folder named 'folder1' and when I will execute following command it will interact with me asking 'are you sure (Y/N)? Y . Its confirming the deletion of folder . What to do?. if I press 'Y' it will delete all the folder inside the named 'Folder1', else if I press 'N' then it will not delete .
C:\>del a
C:\a\*, Are you sure (Y/N)? y
Batch Mode:
It is also called ‘Silent mode’ or ‘Quiet Mode’. The command that operates at batch mode will never interact with the user at any
instance, instead it will take care of every operation by itself.
For example, I am going to explain this by using the same ‘del’ command. There is a switch available for
the ‘del’ command, which makes the command to operate at silent mode, and that switch is ‘/Q’
C:\>del /Q a
C:\>
In this case, the command is not at all interacting with me, whether to delete those file or not.
In the above example, I have tried to delete the same files in the same folder by using the same command
but with a different switch. Anyhow both the commands will perform the same operation but the mode it
operates differs.

nice post....!
ReplyDeleteThis comment has been removed by the author.
ReplyDelete