WHAT IS THE USE OF WINDOW’S BATCH FILE?
By ADMIN| August 6, 2018
CATEGORY : BLOG | BLOG DYNAMIC | BUSINESS TRAVEL | DEV | LATEST NEWS
TAGS :
Every Windows user must have heard about batch files. So what is it exactly? Windows users are aware of command line program Command Prompt or CMD. You can execute actions by entering commands. A batch file works as a layer between CMD and you.It is a file in .cmd, .btm or .bat extensions consisting Command Prompt commands. Whenever you run a batch file, the commands in it are executed in CMD in a sequence. Collectively a set of commands is known as a batch script.
Usage of Batch File
So why do we need to store commands in a batch file? Storing commands in a batch file will not only save time but one doesn’t have to type the same commands again and again. For example, you can set to restart or shut down your Windows computer at a certain time using CMD.If you have created a batch file for this operation, you just need to double-click in order to run the file and Windows will shut down at a set time.This comes in use when you are a developer and want to use CMD on your PC while installing an app, you just need to include batch file in the setup files.When you are creating a batch file, you can use loops, control statements, conditional statements etc. You can run batch file just by typing its name in CMD interface. Also, you can call one batch file from another batch file using CALL command.Batch file modes
The batch-file mode reads a user-created text file which contains one or more directives and runs them one after the other. The file must contain one directive per line.There are certain batch files for which you need to select to continue execution such as Yes or No. This is known as an interactive mode where you need to provide an input to continue. There is another mode, batch mode in which a bat file runs without any interaction with the user.Batch file commands
Before knowing how to create a batch file in Windows computer, it is necessary to know about the Batch commands. It is all about using commands and using them properly to maximizes the usage. Before going further, let’s know about basic commands that are used to make a batch file.Title: Changes the title text on CMD windowEcho: Shows input string as output. You can use ON or OFF option for Echo. This feature when turned on, CMD shows which command is being executed.:: : By adding two colons, you can add a comment in a batch file. CMD overlooks the text written in batch file comment.Cls: Clears the CMD screen.Pause: Stops the Windows batch file’s execution.EXIT: Exit command promptCreate a batch file in Windows 10
The same steps to create a batch file are used in Windows 7,8 or older versions.- Open Notepad. Create a new file.
- Type below mentioned commands in the file:
- The first line echo off is used to turn the display off for all the commands.
- In the second line, title freaksense tutorial will display Freaksense tutorial on top of the CMD screen.
- The next line is a comment or a general remark.
- In the next line, I’ve used echo command to display the string.
- Pause command will ask you to press a key to continue.
- Next two lines will display the strings.
- The last command will exit once you press any key
- Now save the file and replace the extension .bat with .txt.
- Now to run the batch file, double-click it. The Command prompt window will come up with File Explorer Options with required output automatically.
Run A Batch file in Windows 10
One way of executing a .bat extension file is double-clicking the file. However, you can also run the file from CMD interface itself. In order to open a file with CMD, you have to locate it via folder/directory. You need to type the name of the file that you want to open. Lets see the first way.- Double click on the file name.
- CMD commands will be executed instantly.
- After you press any key.
- Press any key again and cmd will exit.