Tuesday, November 22, 2016

What is a batch file ?

Batch file can contain a series of commands which can work on DOS, OS2 and Windows. The batch file can be edited in any notepad application. In short we can say batch file is a script file which contains series of commands, which can be executed by the cmd.exe or command line interpreter.

The batch file name extension can be .bat in DOS and Windows, .btm in specific shell command interpreters and also .cmd.

You can use the below steps to create a sample batch file.

1. If you are using Microsoft windows, open notepad application

2. Copy the below code in the notepad file:

@echo off
SET /p name="Enter your name: "
echo .
echo .
echo Your Name is %name%
Pause

3. Save this text file. After saving close the text file and rename the file extension from .txt to .bat

4. In my case i have saved it as check.bat






5. Double click on this file and it will open a dos window.















We just created a batch file, which asks us for the input and replies with the output. In similar way we can add series of questions and create a interactive batch file.

How the above code works ?

@echo off
This turns off the text which is not required to view, when running a command. e.g. the selected drive path. You can try changing the @echo off to @echo on to see the results.

SET /p name="Enter your name: "
Here we are asking the user to input his/her name. the Set /p command assigns the value of the input to a variable name.

echo .
echo .
Added above code just to create 2 lines, before the output line.

echo Your Name is %name%
Here we are showing the variable name value in the final output line. In order to read the variable by the code interpreter, we need to add % at start and end of the variable. In this case %name%

Pause
We added the Pause code, to pause the window from exiting or executing any other command. If we remove this, the DOS window will exit once we press enter after input line.

Thank you for reading.

Also see:
How to restart google chrome fast and improve system performance ?
WhatsApp launched Video Calling Feature
What is the best free software for video conversion ?
How to convert files into PDF ?
What are the few free must have apps in your system ?

No comments:

Post a Comment