650 likes | 908 Views
Chapter 10. Introduction to Batch Files. Overview. A batch file is a text file that contains an ordered series of commands. Overview. Batch files allow the user to … automate a process create more powerful commands. Concepts of Batch & Interactive Processing.
E N D
Chapter 10 Introduction to Batch Files Ch 10
Overview A batch file is a text file that contains an ordered series of commands. Ch 10
Overview Batch files allow the user to … • automate a process • create more powerful commands Ch 10
Concepts of Batch & Interactive Processing A batch file contains one or more commands. Ch 10
Concepts of Batch & Interactive Processing A batch file must have the extension .BAT Ch 10
Concepts of Batch & Interactive Processing Batch files allow the user to … • minimize keystrokes • minimize the possibility of errors Ch 10
Concepts of Batch & Interactive Processing In interactive processing (real-time mode) … • the user directly interacts with computer • info. is processed without delay Ch 10
How Batch Files Work The difference between Data and Program files is determined by their file extensions. Ch 10
How Batch Files Work Priority rules are followed when the OS looks for a file to load and execute. Ch 10
How Batch Files Work The .BAT extension is the last file extension the OS looks for when trying to execute a program. Ch 10
Using EDIT to Write Batch Files To write a batch file … • must use a program that creates ASCII text files. Ch 10
Using EDIT to Write Batch Files Word processing programs can create text files, but … • they are very large • they take a long time to load into memory Ch 10
Using EDIT to Write Batch Files EDIT is the small, simple text editor in MS-DOS used to write batch files. Ch 10
Using EDIT to Write Batch Files Notepad is the text editor in Windows that can be used to write batch files. Ch 10
Writing and Executing a Batch File to Save Keystrokes It is sometimes easier to use COPY CON instead of EDIT to write a simple batch file. Ch 10
Writing and Executing a Batch File to Save Keystrokes Two drawbacks to using COPY CON: • Cannot correct errors once <Enter> is pressed • Cannot correct errors in existing files Ch 10
Writing and Executing a Batch File to Save Keystrokes Must use EDIT to correct errors. Ch 10
Using Batch FilestoLoad Application Software To launch an application in Windows … • click program icon • select program from menu • use the toolbar Ch 10
Using Batch Files to Load Application Software To launch an application program from the command line … • must create a batch file Ch 10
Using Batch Files to Load Application Software Need to follow three steps in order to load application software in MS-DOS. Ch 10
Writing a Batch File to Load an Application Program By creating a batch file, a user can simplify the process of loading an application program in MS-DOS. Ch 10
Creating Shortcuts for Batch Files on the Desktop To run a batch file from Windows: • click file name in Explorer/My Computer • create shortcut for file and place on desktop Ch 10
Special Batch File Commands There are nine commands specifically designed to be used in batch files. Ch 10
Special Batch FileCommands • CALL • CHOICE • ECHO Ch 10
Special Batch File Commands • FOR • GOTO • IF Ch 10
Special Batch FileCommands • PAUSE • REM • SHIFT Ch 10
The REM Command REM command (remarks)... statements keyed in by user that tell what is the purpose of the batch file Ch 10
The ECHO Command ECHO command … displays a command and the output of that command to the screen. Ch 10
The ECHO Command The default value for ECHO is ON. Ch 10
The ECHO Command Can turn off the display of the command and only see the output of the command. Ch 10
The ECHO Command Ch 10
Activity: Using ECHO Ch 10
The PAUSE Command PAUSE command … instructs the batch file to stop executing until the user takes some action. Ch 10
Stopping a Batch File from Executing Two ways to interrupt a batch file during execution: • Press <Ctrl> + C • Press <Ctrl> + <Break> Ch 10
Replaceable Parameters in Batch Files Many commands use variable or replaceable parameters. Ch 10
Replaceable Parameters in Batch Files Batch files can also use replaceable parameters. Ch 10
Replaceable Parameters in Batch Files Replaceable parameters are used to limit the number of batch files that do the same thing, but use different names. Ch 10
Replaceable Parameters in Batch Files Place holders are needed to indicate to the batch file that a variable (file name) will be keyed in. Ch 10
Replaceable Parameters in Batch Files The place holder used in batch files is the percent sign (%), followed by a number (0-9). Ch 10
Replaceable Parameters in Batch Files The % sign is a signal to the OS that a parameter is coming. Ch 10
Replaceable Parameters in Batch Files The numbers (0-9) indicate what position the parameter is on in the command line. Ch 10