A small Introduction about Batch Programming

What is Batch file?
Batch files are a list of command line instructions that are "batched" together in one file. Most of the command lines can be executed within the command prompt, but batch files make the work load much easier. Batch files can be opened, copied, and edited using notepad.

They are used for simple routines and low-level machine instruction. On Windows, many batch files can be seen within the c:\Windows directory.

Batch files, more or less, make up the backbone of the Windows Operating System. The operating system must have access to these files and be able to add and delete instructions from them. Delete them, and you have effectively disabled the OS.



Basic Batch File Utilities and Commands


Note: Any DOS command can be used within a batch file, below are a list of commands used to support the structure and flow of the batch file

@
Place @ in front of commands that you don't want echoed within the process.

CLS
Clears the screen of any previous data.

CALL
Calls another batch file. Once other batch file isfinished, control is returned to the first (i.e. CALL c:\Windows\Newbat.bat).

BREAK ON/OFF
When turned on within the batch file, the user has an option of stopping the batch file by bressing Ctrl+Break.

GOTO - This command is used to go to another section of the batch file. Sections can be added by adding a colon infront of a name

(i.e. :FIRSTSECTION, :SECONDSECTION):



Quote::FIRSTSECTION
REM Welcome to the first section
GOTO :SECONDSECTION

Quote: :SECONDSECTION
REM Welcome to the second section
GOTO :END
:END

It is possible to loop with the GOTO command:
Quote::START
REM NO!!!!!!!!!!!!!!!!!! IT'S LOOPING!!!!!!!!!!!!!
GOTO :START

PAUSE
The pause command halts a proccess until a key is hit by the user. Displays the message, "Press any key to continue..."

REM
Allows a remark to be placed within the code, displaying a message to the user (i.e. REM HELLO!).

ECHO ON
Command process is shown to user; @ is usually placed before (@ECHO ON).

ECHO OFF
Command process is not shown to the user; @ is usually placed before (@ECHO OFF).

end
Ends the process.


Simple Batch Programming to show Hello message is :

@echo off
echo "hello world"

Type this code into notepad and save it with .bat extenstion(For eg: hello.bat)

By double clicking the batch file,you can run the file. Above batch file will show the hello world but we can' see it. because the window will open and closed within a second.

We will see later how to see it.

Please try to comment if i have done well or if you have finished learning from the blog
EmoticonEmoticon

Comments system