Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that...

63
Ch 10 1 Chapter 10 Chapter 10 Introduction to Batch Files

Transcript of Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that...

Page 1: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 1

Chapter 10Chapter 10

Introduction to Batch Files

Page 2: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 2

OverviewOverview

A batch file is a text file that contains an ordered

series of commands.

Page 3: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 3

OverviewOverview

Batch files allow the user to …

automate a process create more powerful commands

Page 4: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 4

Concepts Concepts ofof Batch Batch & Interactive Processing& Interactive Processing

A batch file contains one or more commands.

Page 5: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 5

Concepts Concepts ofof Batch Batch & Interactive Processing& Interactive Processing

A batch file must have the extension .BAT

Page 6: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 6

Concepts Concepts ofof Batch Batch & Interactive Processing& Interactive Processing

Batch files allow the user to …

minimize keystrokes minimize the possibility of errors

Page 7: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 7

Concepts Concepts ofof Batch Batch & Interactive Processing& Interactive Processing

In interactive processing (real-time mode) …

the user directly interacts with computer info. is processed without delay

Page 8: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 8

How Batch Files How Batch Files WorkWork

The difference between Data and Program files is determined by their file

extensions.

Page 9: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 9

How Batch Files How Batch Files WorkWork

Priority rules are followed when the OS looks for a file to load and execute.

Page 10: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 10

How Batch Files How Batch Files WorkWork

The .BAT extension is the last file extension the OS looks for when trying to

execute a program.

Page 11: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 11

Using Using EDITEDIT to to Write Batch FilesWrite Batch Files

To write a batch file … must use a program that creates ASCII text files.

Page 12: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 12

Using Using EDITEDIT to to Write Batch FilesWrite Batch Files

Word processing programs can create text files, but …

they are very large they take a long time to load into memory

Page 13: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 13

Using Using EDITEDIT to to Write Batch FilesWrite Batch Files

EDIT is the small, simple text editor in MS-DOS

used to write batch files.

Page 14: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 14

Using Using EDITEDIT to to Write Batch FilesWrite Batch Files

Notepad is the text editor in Windows that can be used to write batch files.

Page 15: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 15

Activity:Activity: WritingWritingand Executing aand Executing a

Batch FileBatch File

. . .

Page 16: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 16

Writing and Executing Writing and Executing a Batch File to Save a Batch File to Save

KeystrokesKeystrokes

It is sometimes easier to use COPY CON instead of EDIT

to write a simple batch file.

Page 17: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 17

Writing and Executing Writing and Executing

a Batch File to Save a Batch File to Save KeystrokesKeystrokes

Two drawbacks to using COPY CON:

Cannot correct errors once <Enter> is pressed Cannot correct errors in existing files

Page 18: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 18

Writing and Executing Writing and Executing a Batch File to Save a Batch File to Save

KeystrokesKeystrokes

Must use EDIT to correct errors.

Page 19: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 19

Activity:Activity: Writing andWriting andExecuting a One-Executing a One-Letter Batch FileLetter Batch File

. . .

Page 20: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 20

Using Batch FilesUsing Batch Files toto Load Application Load Application

SoftwareSoftwareTo launch an application in Windows …

click program icon select program from menu use the toolbar

Page 21: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 21

Using Batch Files to Using Batch Files to Load Application Load Application

SoftwareSoftwareTo launch an application program from the command line …

must create a batch file

Page 22: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 22

Using Batch Files to Using Batch Files to Load Application Load Application

SoftwareSoftware

Need to follow three steps in order to load application

software in MS-DOS.

Page 23: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 23

Activity:Activity: Using theUsing theHPB ApplicationHPB Application

PackagePackage

. . .

Page 24: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 24

Writing a Batch File Writing a Batch File to Load an to Load an

Application ProgramApplication Program

By creating a batch file, a user can simplify the process of

loading an application program in MS-DOS.

Page 25: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 25

Activity:Activity: Writing aWriting aBatch File to ExecuteBatch File to Execute

HPBHPB

. . .

Page 26: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 26

Creating Shortcuts for Creating Shortcuts for Batch Files on the Batch Files on the

DesktopDesktopTo run a batch file from Windows:

click file name in Explorer/My Computer create shortcut for file and place on desktop

Page 27: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 27

Activity:Activity: CreatingCreatinga Shortcut on thea Shortcut on the

DesktopDesktop

. . .

Page 28: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 28

Special Batch File Special Batch File CommandsCommands

There are nine commands specifically designed to be used in batch files.

Page 29: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 29

Special Batch FileSpecial Batch FileCommandsCommands

CALL CHOICE ECHO

Page 30: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 30

Special Batch File Special Batch File CommandsCommands

FOR GOTO IF

Page 31: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 31

Special Batch FileSpecial Batch FileCommandsCommands

PAUSE REM SHIFT

Page 32: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 32

The REM CommandThe REM Command

REM command (remarks)...statements keyed in by user that tell what is the purpose of the batch file

Page 33: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 33

Activity:Activity: UsingUsingREMREM

. . .

Page 34: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 34

The The ECHOECHO CommandCommand

ECHO command …

displays a command and the output of that command

to the screen.

Page 35: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 35

The The ECHOECHO CommandCommand

The default value for ECHO is ON.

Page 36: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 36

The The ECHOECHO CommandCommand

Can turn off the display of the command and only see the output of the command.

Page 37: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 37

The The ECHOECHO CommandCommand

Page 38: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 38

Activity:Activity: UsingUsingECHOECHO

. . .

Page 39: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 39

Activity: Activity: Using Using ECHOECHO

Page 40: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 40

The The PAUSEPAUSE CommandCommand

PAUSE command …instructs the batch file to stop executing until the user takes some action.

Page 41: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 41

Activity:Activity: UsingUsingPAUSEPAUSE

. . .

Page 42: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 42

Stopping a Batch File Stopping a Batch File from Executingfrom Executing

Two ways to interrupt a batch file during execution:

Press <Ctrl> + C Press <Ctrl> + <Break>

Page 43: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 43

Activity:Activity: Quitting aQuitting aBatch FileBatch File

. . .

Page 44: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 44

Replaceable Replaceable Parameters in Batch Parameters in Batch

FilesFiles

Many commands use variable or replaceable

parameters.

Page 45: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 45

Replaceable Replaceable Parameters in Batch Parameters in Batch

FilesFiles

Batch files can also use replaceable parameters.

Page 46: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 46

Replaceable Replaceable Parameters in Batch Parameters in Batch

FilesFilesReplaceable parameters are

used to limit the number of batch files that do the

same thing, but use different names.

Page 47: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 47

Replaceable Replaceable Parameters in Batch Parameters in Batch

FilesFilesPlace holders are needed to

indicate to the batch file that a variable (file name)

will be keyed in.

Page 48: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 48

Replaceable Replaceable Parameters in Batch Parameters in Batch

FilesFilesThe place holder used in batch files is the percent sign (%), followed by a

number (0-9).

Page 49: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 49

Replaceable Replaceable Parameters in Batch Parameters in Batch

FilesFilesThe % sign is a signal to the OS that a parameter is

coming.

Page 50: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 50

Replaceable Replaceable Parameters in Batch Parameters in Batch

FilesFilesThe numbers (0-9) indicate

what position the parameter is on in the

command line.

Page 51: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 51

Activity:Activity: UsingUsingReplaceableReplaceableParametersParameters

. . .

Page 52: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 52

Multiple Replaceable Multiple Replaceable Parameters in Batch Parameters in Batch

FilesFilesMany commands used in

batch files may require more than one parameter.

Page 53: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 53

Multiple Replaceable Multiple Replaceable Parameters in Batch Parameters in Batch

FileFileBatch files can have up to 10 replaceable parameters

(%0-%9).

Page 54: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 54

Activity:Activity: UsingUsingMultiple ReplaceableMultiple Replaceable

ParametersParameters

. . .

Page 55: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 55

Activity: Activity: Using Using Multiple Replaceable Multiple Replaceable

ParametersParameters

Page 56: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 56

Creating Useful Creating Useful Batch FilesBatch Files

With batch files a user can create new commands that

are not provided by the OS.

Page 57: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 57

Activity:Activity: WritingWritingUseful Batch FilesUseful Batch Files

. . .

Page 58: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 58

Understanding Understanding AUTOEXEC.BATAUTOEXEC.BAT

AUTOEXEC.BAT is a file that …

runs when the system is booted contains specific commands that a user chooses to run

Page 59: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 59

Understanding Understanding AUTOEXEC.BATAUTOEXEC.BAT

Interactive booting …user is asked by the computer if s/he wants to execute each line in the CONFIG.SYS and AUTOEXEC.BAT files.

Page 60: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 60

Activity:Activity: Writing andWriting andUsing anUsing an

AUTOEXEC.BATAUTOEXEC.BAT File File

. . .

Page 61: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 61

Controlling the Controlling the Boot ProcessBoot Process

During booting process, the user may experience problems that are related to instruction

statements in the CONFIG.SYS or AUTOEXEC.BAT files.

Page 62: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 62

Controlling the Controlling the Boot ProcessBoot Process

By pressing certain function keys, the user can control

the boot process in order to correct problems that arise.

Page 63: Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.

Ch 10 63

Activity:Activity: BypassingBypassingAUTOEXEC.BATAUTOEXEC.BAT

. . .