Sections: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Index | Next >
Learning objective: (2) Explain the purpose of a batch file
As you go through this unit, keep in mind that we are not learning MS-DOS but the command line interface of Windows which is *based* on MS-DOS. The commands and concepts of the command line interface (CLI) of Windows are based on the use of MS-DOS commands for backwards compatibility. The more you know about MS-DOS, the better prepared you will be to understand the CLI of Windows.
In MS-DOS and Windows, a batch file is a text file containing a series of commands intended to be executed by the command interpreter. When a batch file is run, the shell program (usually CMD.EXE or COMMAND.COM) reads the file and executes its commands, normally line-by-line. Batch files are useful for running a series of executables automatically. Many system administrators use them to automate tedious processes. Although batch files support elementary program flow commands such as if and goto, they are not well-suited for general-purpose programming. Batch file are ASCII file. The contain a series of DOS commands just as if you were typing them in by hand at the DOS prompt. They end with a .BAT extension. Once introduced to your system, batch files basically become DOS commands for your system.
AUTOEXEC.BAT
In MS-DOS, a batch file can be started from the command line by typing its name followed by any required parameters and pressing the "enter" key. When MS-DOS loads, the file AUTOEXEC.BAT is automatically executed, so any commands that need to be run to set up the MS-DOS environment for use could be placed in this file. Computer users would have the autoexec file set up the system date and time, initialize the MS-DOS environment, load any resident programs or device drivers, or initialize network connections and assignments. [Wikipedia]
This example represents a modest batch file. It is made up of the commands to copy com files from the C drive to the \111\com as a backup. The top portion of the batch file uses special batch file commands that will be covered in this unit. The lower half of this batch file lists the DOS commands used to backup the com files.
When the batch file is executed, note the output of each line from the batch file to the screen. When executing batch files, I recommend you use the full name, ending with bat, to minimize any confusion as to which file you want to execute based on the succession of commands since the batch file is now a system command on your computer.
@ECHO
The @ECHO command suspends the echo effect for the ECHO command which turns off the echo effect for the remainder of the batch file.
REM
The REM command allows developers to enter a comment into the batch file which will only be seen when the code is opened in a text editor.
ECHO
The ECHO command will allow text and other events to be displayed to the console during execution.
Thinking: Why sequence a series of DOS commands in a single file?
Key terms: .BAT, AUTOEXEC.BAT, batch file, commands
Resources:
To maximize your learning, please visit these Web sites and review their content
to help reinforce the concepts presented in this section.
Quick links:
Batch files @ Wikipedia
Batch Files (Scripts) in Windows @ commandwindows.com
Notes on navigation: Click inside the frame to navigate the embedded Web page. - Click outside the frame to navigate this page to scroll up/down between the embedded Web pages. - Click on the frame title to open that page in a new tab in most browsers. - Click on the the "Reload page" link to reload the original page for that frame.
Batch files @ Wikipedia |
Reload page
|
If frame is empty, click on the link to view the page in a new tab or window
Batch Files (Scripts) in Windows @ commandwindows.com |
Reload page
|
If frame is empty, click on the link to view the page in a new tab or window
Sections: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Index | Next >