Sunday, June 13, 2010

My simple batch file tutorial [Part 3]

In this part of tutorial, I am going to teach about the essential part of batch programming

@echo off
echo Hello World !
pause


"echo off"  is the command which hides the prompt of where the bat files is launched ; e.g (C:/ >),
sure you can turn on the echo off (Prompt display) but it will shows every line of the assembly code (it will work at simple programming level but it definitely won't work at more advance level) and it will be a little bit messy for the user.




 The above figure shows what happens when you do not include "@echo off"

I include the more variance of the sample Hello World ! programs.

V1:

@echo off
echo Hello World !
pause 


V2:


@ECHO OFF
ECHO Hello World!
PAUSE


If you test the both batch samples, the programs should actually works in Vista as batch programming is case insensitive in nature.


"echo" on other hand is the command which display the result from the batch programs to the output. 
You can use the echo to broadcast any messages you like or  even display the output after receives input from the user.


If you ever learnt C programming language, it is very similiar to printf command. 


You can try to customize the messages into your own style such as below.




@echo off
echo ######################################
echo # Welcome to zeushammer.blogspot.com #
echo ######################################
pause



You can broadcast any kind of messages as long as it is ANSI supported characters. 
Now we move on to the last components of batch programmings

"pause" is the command which pause all the current operations while waiting for user input. 


The purpose of pause command is to hold all the operations while waiting for users to input to proceed. (P.S: It is not always necessary means to end the programs). It will be marked by : "Press any keys to continue . . . "


If you try to program without using pause , the program will simply end itself and you can't even view the messages broad casted. :( 


In the next tutorial part, I will teach you how to customize the batch programs display.

No comments:

Another random post to read ? Come !

Related Posts with Thumbnails