Batch Commands
|
Batch Commands in batch files
|
| @
|
Does not echo back the text after the
at symbol. This is most commonly used as @ECHO OFF
to prevent any of the commands in the batch file from being
displayed just the information needed. |
| %1
|
Variables can be inserted into a batch
structure in the form of command line arguements. These are in the
form %1, %2, etc. To populate the variables, type
the desired values after the batch file name when executing it. The
following is a batch file example:
echo Hello %1
When the above one line batch file is created and adding your name
after the batch file. For example typing myname (being the name of
the bat file) and then your name:
myname bob
would output:
Hello bob |
| :LABEL
|
By adding a colon in front of a word
such as LABEL you create a category, more commonly
known as a label. Then you can skip to certain sections of a batch
file such as the end of the batch file. Also see
GOTO. |
| CALL
|
Calls another batch file and then
returns control to the first when done.
CALL C:\WINDOWS\NEW_BAT.BAT
Call another program.
CALL C:\WINDOWS\System32\calc.exe
|
| CHOICE
|
Allows user input. Default is Y or N.
You may make your own choice with the /C: switch.
The following is a batch file example:
@ECHO OFF
CHOICE /C:123
IF errorlevel 3 goto THREE
IF errorlevel 2 goto TWO
IF errorlevel 1 goto ONE>
:ONE
ECHO One
PAUSE
EXIT
:TWO
ECHO Two
PAUSE
EXIT
:THREE
ECHO Three
PAUSE
EXIT
|
| CLS
|
Clears the screen. |
| ECHO
|
Setting ECHO "on" will display the
batch process to the screen, setting it to "off" will hide the
batch process. ECHO can also be used in batch file to send output
to the screen:
@ECHO OFF
ECHO Hello
PAUSE
ECHO. sends a blank line |
| EXIT
|
Exits out of the DOS window if the
batch file is run from Windows. |
| GOTO
|
Used to go to a certain label such as
LABEL. An example of GOTO would
be to GOTO SUBSECTION. |
| IF
|
Used to check for a certain condition
if the condition exists. If that condition exists, it will perform
that function. The following is a batch file example:
@ECHO OFF
:START
COPY file.txt file2.txt
IF errorlevel 1 GOTO MKFILE
GOTO :END
:MKFILE
ECHO file text>file.txt
GOTO START
:END
ECHO Quitting
PAUSE
|
| PAUSE
|
Prompt the user to press any key to
continue. |
| REM
|
You can place comments (remarks) into
the batch file without displaying or executing that line when the
batch file is run. |
| SHIFT
|
Changes the position of replaceable
parameters in a batch program. |
| START
|
Used for Windows 95, Windows 98 and
Windows NT 4.0 and above to start a windows application such as
START C:\WINDOW\CALC would run the Windows
Calculator. |
|
Depending on the
version of DOS you are using, either type in HELP and the
command-name or type in the command-name and /? to receive help on
the command.
Copyright © ScriptCode.com 2010. All rights reserved.