Batch File Programming Tutorial#2

Batch File Programming

Tutorial #2

 HI GUYS !!! Today were going to learn how to create markers and how to make the user input data .

MARKERS

 What are markers ???

They are specified points/line  in a commands which have been marked, so that they can be  called on later during the execution.

How to make a marker ???

            Its simple  to create a marker you have to write  “:” followed by the marker’s name for              eg. “ :marker_name ”

How do we use them  ???

We use them with the “ GOTO ” command . The “ GOTO ” command , does exactly what it means !! It goes to the specified point to which it has been referred to (The marker)

EXAMPLE

[sourcecode]<br />@ECHO OFF<br />: MARK<br />ECHO HELLO WORLD !!!<br />PAUSE<br />GOTO MARK<br />[/sourcecode]

1 Batch File Programming Tutorial#2 batch file programming  void Tutorial std spotlight space sourcecode sign programming point pause markers marker language iostream input data Infinite GOTO File execution cpp Batch File Programming 

OUTPUT

            This program is in infinite loop so this will never end .

            WARNING !!!  : Never use the START command with this type of infinite loops . If you do so you will crash your system.

VARIABLES

To create a variable you need to initialize it at the point of creation itself . To create a variable we use the set command. There should be no space in between variable_name and “=” sign. If you are using the variable other than directly to any command you need to enclose them in between”%”.              “%variable_name%”

                        Syntax: set variable_name=2

            EXAMPLE

[sourcecode]<br />@ECHO OFF<br />set x=2<br />echo %x%<br />set y=%x%+2<br />echo %y%<br />set z=y+x //This will give a different value<br />echo %z%<br />[/sourcecode]

3 Batch File Programming Tutorial#2 batch file programming  void Tutorial std spotlight space sourcecode sign programming point pause markers marker language iostream input data Infinite GOTO File execution cpp Batch File Programming 

INPUT DATA FROM USER

            To input data we use the set  command .

            Syntax: set /p variable_name=

            /p is used to pause the execution until the user does an input and presses enter. There should be no space in between variable_name and “=” sign.

            Exmaple

[sourcecode]<br />@echo off<br />echo Enter Your name :<br />set /p a=<br />[/sourcecode]

2 Batch File Programming Tutorial#2 batch file programming  void Tutorial std spotlight space sourcecode sign programming point pause markers marker language iostream input data Infinite GOTO File execution cpp Batch File Programming 

With this we have learnt how to create markers and how to make the user input data and how to create and interact with variables . Next time we will be learning how to create loops.

Authors bio is coming up shortly.
Abhishek Unnikrishnan tagged this post with:
, , , , , , , , , , , , , , , , , , , ,
Read 14 articles by
Close
Please support the site
By clicking any of these buttons you help our site to get better

Twitter

Facebook

Google+