Chapter 11
Download
1 / 73

Chapter 11 - PowerPoint PPT Presentation


  • 162 Views
  • Uploaded on

Chapter 11. Advanced Batch Files. Overview. This chapter focuses on batch file commands that allow you to: write sophisticated batch files further refine your technique in working with the environment . Batch File Commands. Batch files must …

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Chapter 11' - garth


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Chapter 11
Chapter 11

Advanced Batch Files

Ch 11


Overview
Overview

This chapter focuses on batch file commands that allow you to:

  • write sophisticated batch

    files

  • further refine your

    technique in working with

    the environment

Ch 11


Batch file commands
Batch File Commands

Batch files must …

  • have the file extension

    .BAT

  • be an ASCII text file

  • include legitimate

    commands

Ch 11


Batch file commands1
Batch File Commands

Any command used at the command line can be used in a batch file.

Ch 11


Batch file commands2
Batch File Commands

Batch files have …

  • a limited vocabulary

    (commands)

  • a syntax

  • programming logic

Ch 11


A review of the rem pause and echo commands
A Review of the REM, PAUSE, and ECHO Commands

REM command (remarks)…

statements keyed in by user that tell what is the

purpose of the batch file.

Ch 11


A review of the rem pause and echo command
A Review of the REM, PAUSE, and ECHO Command

PAUSE command …

instructs the batch file to stop executing until the

user takes some action.

Ch 11


A review of the rem pause and the echo command
A Review of the REM, PAUSE, and the ECHO Command

Two ways to interrupt a batch file during execution:

  • Press <Ctrl> + C

  • Press <Ctrl> + <Break>

Ch 11


A review of the rem pause and the echo command1
A Review of the REM, PAUSE, and the ECHO Command

ECHO command …

displays a command and the output of that

command to the screen.

Ch 11


A review of the rem pause and the echo command2
A Review of the REM, PAUSE, and the ECHO Command

When ECHO is ON:

  • all commands in a

    batch file are

    displayed on the

    screen.

Ch 11


A review of the rem pause and the echo command3
A Review of the REM, PAUSE, and the ECHO Command

When ECHO is OFF …

  • can see the output of

    the command, but not

    the command itself.

Ch 11


Advanced features of echo and rem
Advanced Features of ECHO and REM

To save valuable processing time, use a double colon (::) instead of the REM command.

Ch 11


Advanced features of echo and rem1
Advanced Features of ECHO and REM

To delete the display of even the message “1 file(s) copied”, use the device NUL.

Ch 11


Advanced features of echo and rem2
Advanced Features of ECHO and REM

Using NUL will not suppress a message such as “file not found”.

Ch 11


Advanced features of echo and rem3
Advanced Features of ECHO and REM

To suppress all messages use the command CTTY NUL.

Ch 11


Advanced features of echo and rem4
Advanced Features of ECHO and REM

When CTTY NUL is used, must follow with CTTYCON in order to have control of the console.

Ch 11


Advanced features of echo and rem5
Advanced Features of ECHO and REM

There is no such thing as a blank line in batch files.

Ch 11


Advanced features of echo and rem6
Advanced Features of ECHO and REM

To insert a blank line, key in ECHO followed by a period (ECHO.)

Ch 11



The goto command
The GOTO Command

GOTO command …

  • will branch to a new

    line, creating a loop

  • works in conjunction

    with a label

Ch 11


The goto command1
The GOTO Command

A loop will repeat steps until it is stopped by …

  • using an IF statement

  • breaking into the batch

    file with <Ctrl> + C

Ch 11


The goto command2
The GOTO Command

A label …

  • is preceded by a colon

    (:)

  • can be no longer than

    8 characters

  • is not a command

Ch 11


The goto command3
The GOTO Command

GOTO has one parameter …

  • GOTO label

Ch 11



The shift command
The SHIFT Command

The SHIFT command allows for an unlimited number of parameters on the command line.

Ch 11


The shift command1
The SHIFT Command

SHIFT command …

changes the position of the replaceable parameter

in a batch file.

Ch 11



The if command
The IF Command

IF command …

allows for conditional processing.

Ch 11


The if command1
The IF Command

Conditional processing …

compares two items to determine if they are

identical, or if one is

greater than the other.

Ch 11


The if command2
The IF Command

The result of comparison testing is either a True or False value.

Ch 11


The if command3
The IF Command

True = items are identical

False = items are not identical

Ch 11


The if command4
The IF Command

Syntax of IF command:

IF <condition> <command>

Ch 11


The if command5
The IF Command

If a condition is True, the command will be executed.

If a condition is False, the command will not be executed.

Ch 11


The if command6
The IF Command

The IF command checks for three conditions.

Ch 11


If command using strings
IF Command Using Strings

To test whether or not one character string is exactly the same as another, use the IF command.

Ch 11


If command using strings1
IF Command Using Strings

The strings to be compared are separated by two equal signs (= =).

Ch 11



Testing for null values
Testing for NULL Values

In a batch file it is sometimes possible to be caught in an endless loop.

Ch 11


Testing for null values1
Testing for NULL Values

A value equal to “nothing” must be placed in a batch file to indicate when to end.

Ch 11


Testing for null values2
Testing for NULL Values

NULL values …

a user-defined value equivalent to nothing (no data).

Ch 11


Testing for null values3
Testing for NULL Values

Testing for a null value involves using the IF command with quotation marks.

Ch 11


Testing for null values4
Testing for NULL Values

Use quotation marks to test for null value:

IF “%1” = = GOTO LABEL

Ch 11


Testing for null values5
Testing for NULL Values

“If nothing is there, GOTO somewhere else”

Ch 11



The if exist if not exist command
The IF EXIST/IF NOT EXIST Command

IF EXIST/IF NOT EXIST command:

checks for the existence or non-existence of a file.

Ch 11



The if errorlevel command testing
The IF ERRORLEVEL Command Testing

Exit code …

a code set by a program that indicates a True or False condition when

the program finishes

executing.

Ch 11


The if errorlevel command testing1
The IF ERRORLEVEL Command Testing

IF ERRORLEVELcommand…

a statement in a batch file that can test exit codes.

Ch 11


The if errorlevel command testing2
The IF ERRORLEVEL Command Testing

An exit code is tested with ERRORLEVEL to determine if it is greater than or equal to it.

Ch 11



Writing programs to test for key codes
Writing Programs to Test for Key Codes

Exit codes can be …

  • set by an operating

    system program

  • created by writing a

    small program

Ch 11


Writing programs to test for key codes1
Writing Programs to Test for Key Codes

To write a program a user can …

  • use a programming

    language

  • use an OS utility

    called DEBUG

Ch 11


Writing programs to test for key codes2
Writing Programs to Test for Key Codes

Easiest way to use DEBUG is to create a script file.

Ch 11


Writing programs to test for key codes3
Writing Programs to Test for Key Codes

Script file …

a set of instructions that can be written in any text

editor.

Ch 11



The choice command
The CHOICE Command

CHOICE command …

prompts the user to make a choice.

Ch 11


The choice command1
The CHOICE Command

Syntax for CHOICEcommand:

CHOICE [/C[:]choices] [/N] [/S]

[/T[:]c,nn] [text]

Ch 11



The environment
The Environment

The environment …

  • is an area that the OS

    sets aside in memory

  • holds important info.

    that the OS needs to

    know

Ch 11


The environment1
The Environment

Application programs can …

  • read any items in the

    environment

  • post their own messages

    there

Ch 11


The environment2
The Environment

A user can leave a message there through …

  • the AUTOEXEC.BAT

    file

  • other batch files

  • the command line

Ch 11


The environment3
The Environment

To leave a message, use the SET command.

Ch 11


The environment4
The Environment

Syntax for SET command …

SET [ variable = [string] ]

Ch 11



The dircmd environmental variable
The DIRCMD Environmental Variable

The DIRCMD command variable allows the user to preset, or change the way DIR displays information.

Ch 11



The for in do command
The FOR..IN..DO Command

The FOR..IN..DO command can be …

  • issued at the command

    line

  • placed in a batch file

Ch 11


The for in do command1
The FOR..IN..DO Command

FOR allows the use of a single command to issue several commands at once.

Ch 11


The for in do command2
The FOR..IN..DO Command

Syntax for the FOR..IN..DO command at the command line:

FOR %variable IN (set) DO

command [command-parameters]

Ch 11


The for in do command3
The FOR..IN..DO Command

Syntax for the FOR..IN..DO command in a batch program:

FOR %%variable IN (set) DO

command [command-parameters]

Ch 11



The call command
The CALL Command

CALL command …

calls (executes) one batch program from another

without causing first

batch program to stop.

Ch 11



ad