home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 September
/
Simtel20_Sept92.cdr
/
msdos
/
batutl
/
battutor.arc
/
_ELEM.REM
next >
Wrap
Text File
|
1983-08-28
|
9KB
|
155 lines
Text File _elem.rem
Here's a short list of journal articles and other references to get you
started.
A two-part tutorial on Batch Files appears in the "System Notebook" column of
SOFTALK magazine, October and November, 1982. In general, back issues of
SOFTALK are an excellent source of information for the neophyte PC user.
A very interesting application of the DOS 2.0 Batch File capabilities can be
found in Tom Sheldon's "One from Column A, One from Column B", PC WORLD
magazine, Vol. 1, Number 5.
Of course, the definitive source of information remains the DOS 2.0 Manual
itself, pp. 6-28 to 6-49.
For those of you who are anxious to write your first Batch Files and who don't
have access to the above references, here is a "micro-tutorial".
We'll assume that you are familiar with the idea of the DOS prompt "A>" being a
request from the DOS command processor for the name of an executable file to
load and run, such as DOS's FORMAT, DISKCOPY, BASICA, or any other executable
file such as a word processor, spread sheet program, and the like; or for the
name of an internal command, such as TIME, DATE, DIR, COPY, PATH, etc, that the
command processor itself executes. Every time you see the A> prompt (or B>,
etc), DOS is quietly listening to the keyboard for the next command to be
entered. When you enter a command line in answer to this prompt, DOS then
either executes the command directly or else loads and runs a program. In
either case, when the "process" that the command evokes has run to completion,
DOS regains control of the PC and displays its prompt and quietly waits for
another command from you.
Some users hardly ever talk directly to DOS, spending most of their time in the
execution of applications programs. Other users may have extensive dialogues
with DOS, using commands whose syntax is often difficult to remember and
in which a misspelled name or misplaced character can spell disaster.
When your use of the PC involves command dialogues with DOS (copying disks,
copying files, looking at directories, calling a series of language processors
for program development, etc), then after a while you'll notice that you are
using some sequences of commands over and over again, perhaps with just a
change of a filename or other parameters. Wouldn't it be nice to type that
sequence of DOS command lines just one more time, put a label on it, and then
magically execute the entire sequence by simply typing its label, perhaps even
dubbing a filename into some of the commands so that you could run the same
sequence of commands with different files. That is exactly what a Batch File
does for you, plus a lot more.
Here are the mechanics of creating this labeled sequence of commands that we
call a Batch File. First, ask DOS to run your favorite text editor that
produces "DOS-compatible ascii text files" without a lot of fancy control
characters imbedded in the text. Examples of text editors that create such
files are DOS's own EDLIN (a limited but adequate line editor), Volkswriter
with "programmer's margins", WORDSTAR in "non-document" mode, VEDIT, The
Personal Editor, and a host of public domain editors. An example of a "text
editor" (word processors are just glorified text editors) that DOES NOT
directly create clean text files is Easy Writer II.
When you have mastered a text editor well enough to correctly enter and edit a
few lines of text, then type the sequence of DOS commands that you wish to
"automate", line by line, just as you would if you were entering them in
response to the DOS ">" prompt. Finally, tell the text editor to store these
lines in a file with a filename that has a ".BAT" extension, such as FOO.BAT.
Now, the fun starts. Remember that whenever you see the DOS ">" prompt, you
can give DOS the name of any executable file and DOS will run it for you. The
filenames that DOS recognizes as executable are those ending with .COM, .EXE,
and, you guessed it, .BAT . So answer the DOS prompt with FOO (you don't type
the .BAT, just as you don't type the .COM when you ask for the FORMAT
command).
As DOS begins to execute your Batch File, it displays the familiar ">" prompt
on the screen. But now, instead of waiting patiently by the keyboard for your
response, DOS reads the first line of text from your FOO.BAT file, displays it
on the screen, and immediately executes it, just as if you had typed it
(lightning quick) as a response to the ">". DOS has, in effect, replaced the
keyboard with the FOO.BAT file as the place it goes to get a response to its
">" prompt. Any programs that are run by your command lines in the FOO.BAT file
are free to use the keyboard, but DOS itself gets its commands from the FOO.BAT
file until the list of command lines is exhausted.
This appears to be a pretty good way to enter some long command line sequences,
or command lines that tax the most accurate typist. But there is much more to
Batch Files than saving keystrokes. When you create the Batch File FOO.BAT,
you can insert "place-holders" (or formal parameters) in the command lines for
information that will be known only at the time that the Batch File is run.
For example, if you want a command line in a Batch File to always copy a file
with the basic extension .BAS from drive A: to drive B: and change its
extension to .SAV at the same time, you could use the following Batch File
command line:
copy a:%1.bas b:%1.sav
The "%1" is a place-holder for a string of characters that will be substituted
into the command line later when the Batch File is executed. If this line were
created and saved in the file called SAVIT.BAT, then in order to perform the
above operation on the Basic file MYFILE.BAS, you would type the command:
A> savit myfile
DOS will now run the SAVIT.BAT file, and, whenever it arrives at a place-holder
"%1", it will substitute the first parameter found on the SAVIT command line,
namely MYFILE in this example. The command line that will therefore be executed
from the Batch File is the following:
copy a:myfile.bas b:myfile.sav
SAVIT.BAT now becomes a general tool for doing this particular file operation.
This is a simple operation, but you can see that there is a powerful capability
to save you time, keystrokes, and damage from mistakes, by putting repetitive
sequences of DOS commands into Batch Files.
With the release of DOS 2.0, Batch Files have been given looping, testing, and
branching (GOTO) subcommands to program the flow of control through the command
lines. Now a Batch File is no longer limited to a "linear" list of command
lines that is executed one time only. You can create arbitrarily complex
"command line programs" that make decisions during the Batch File execution
based upon intermediate results. In fact, the purpose of the utilities on this
disk is to expand the scope of the information that an executing Batch File can
obtain in order to make branching decisions. But more on that later.
One special Batch File worth noting is called the AUTOEXEC.BAT file. This is a
"reserved filename", meaning that this file, if it exists, gets special
treatment from DOS. Whenever DOS is "booted" (that is, whenever you turn on
the PC or start over again by typing CTRL-ALT-DEL), DOS will go look on the A:
drive for a file with this name and, if found, will execute all of the commands
in this special Batch File before turning control over to you with the ">"
prompt. The AUTOEXEC.BAT file is a convenient means to do initializing tasks
automatically, such as reading the time and date from a hardware
clock-calendar, or creating a RAM disk. Some applications programs, such as
Volkswriter, supply an AUTOEXEC.BAT file that immediately calls the application
program, obviating your need to talk to DOS at all. You turn on the computer,
and it jumps into the word processor.
The best way to learn how to create and execute Batch File is ... to create
some and execute them. We encourage you to stop the tutorial at this point and
try your hand at it. Write and execute a few Batch Files until you get the
hang of it, then restart this tutorial. If you're unfamiliar with any text
editors or word processors that operate in "programming" mode, then EDLIN would
be a good one to master, since it comes with DOS and is adequate for creating
small files.
If, however, you have a pretty good grasp of the mechanics of creating and
executing a Batch File (or you're just plain impatient to see what else is on
this disk), that's ok, too. But you might skim over the DOS 2.0 Manual's
pages 6-28 to 6-49, to get yourself oriented for the ensuing discussion.
So ...
u&╟ ïFⁿÄ^■ïσ]╦MW_ZTRUNC Uï∞╕εÄ╪+└PìFPèF*ΣPÜ σâ─Ä^■ïσ]╦MW_FILE_TIMESUï∞╕εÄ╪╕ε