Category : Batch File Utilities - mostly for DOS
Archive   : BATDOC.ZIP
Filename : BH_4.DOC

 
Output of file : BH_4.DOC contained in archive : BATDOC.ZIP


BAT-HINT # 4

**************************************************************************

from the BATHINTS library... part of the BATPOWER CONFERENCE from:

THE PAINFRAME OPUS/FIDO 261/1004

Baltimore, Maryland 1-301-488-7461

**************************************************************************

The ENVIRONMENT and its VARIABLES

No, this is not about the weather... but it is a stormy subject for many
users. DOS has a user variable area of memory called the ENVIRONMENT that
is used to store certain types of variables... environmental variables...
whose values are made available to programs. These variables include the
directory path (path variable), the command processor specification
(comspec variable) and the system prompt (prompt variable). Typing the
SET command alone will reveal the values of your current environmental
variables and will always include the COMSPEC= variable. If your prompt is
the DOS default prompt, that variable will not be displayed. The value of
the prompt environmental variable is only displayed by the SET command if
you have set the prompt to a new value.

The default capacity of the ENVIRONMENT is 160 bytes for DOS 3.X. This
capacity can be expanded throught the use of the SHELL command in the
config.sys file (see BATHINT file bh_1.doc). The capacity of the
ENVIRONMENT defines the maximum number of bytes that can be present in the
ENVIRONMENT, but DOS expands the ENVIRONMENT as necessary for holding the
values of additional ENVIRONMENTAL VARIABLES. However, this is true only
when there are no memory resident programs loaded in memory. Once a memory
resident program is loaded, DOS cannot expand the capacity of the
ENVIRONMENT beyond 128 bytes, since memory resident programs are loaded
above the memory area earmarked for the ENVIRONMENT. Therefore, using an
expanded ENVIRONMENT is essential if you are running memory resident
programs and also want to SET a long directory path or SET the value of
other custom ENVIRONMENTAL VARIABLES.

With an expanded ENVIRONMENT, many variables can be given values using the
SET command and the value of those variables can be called up for use when
needed. Why use ENVIRONMENTAL VARIABLES? Perhaps the best use of the
ENVIRONMENTAL VARIABLE is ridding your system once and for all of that
painful message... Insert disk with command.com. For hard disk users, this
is not much of a problem since command.com resides on a fixed disk. But for
floppy users... Shown below are command lines: one to be placed in the
config.sys file and the other to be placed in your autoexec.bat file:

CONFIG.SYS AUTOEXEC.BAT

shell=command.com /e:62 /p copy command.com d:\
set comspec=d:\command.com

The config.sys expands your ENVIRONMENT to the maximum 962 bytes allowable
under DOS 3.1 and the command lines in the autoexec.bat copy the command
processor to your RAM disk d: (you have one don't you?) then sets the value
of COMSPEC (the commmand processor ENVIRONMENTAL VARIABLE) to the the
command.com that was copied into the RAM disk. Now whenever a program needs
to access command.com it will always be found... in the RAM disk (until you
turn off your cpu). Place these commands near the top of your config.sys
and autoexec.bat files.

The third line in your autoexec.bat file should SET the value of the PATH
ENVIRONMENTAL VARIABLE. Either of the two command lines shown below will
SET your PATH to the indicated value:

set path=d:\;c:\bat;c:\dos;c:\util or
path=d:\;c:\bat;c:\dos;c:\util

Use of the SET command is not necessary for either the PATH or PROMPT
ENVIRONMENTAL VARIABLES.

A fantastic little program written by Frank Schweiger is ANSWER.COM. This
program and its documentation have been bundled with several other useful
programs in the BATPOWER CONFERENCE file BATPOWER.ARC. When used in a batch
file, ANSWER pauses execution of the batch file, displays an optional
message string following the ANSWER command and accepts input from the
standard device (i.e. the console...) until a carriage return is sent (ASCI
13). ANSWER then sets the value of the ANSWER ENVIRONMENTAL VARIABLE to the
input received between pausing and the carriage return. This allows the
user at the console to enter ENVIRONMENTAL VARIABLES that can be used or
tested at a later time. For example, assuming that ANSWER.COM is in the
current directory or can be found in the directory path, the following
sample.bat file waits for input from the console:

SAMPLE.BAT

echo off
answer What is your name?

The user might type the letters... John, then press return. The next few
lines in the batch file might then be:

cls
echo Your name is %answer%

The monitor would then display the following statement:

Your name is John

Simple enough, but now you have this guys name in the ENVIRONMENT. Thus,
each and every time you wish to refer to this user you need only call up
the ENVIRONMENTAL VARIABLE assigned the value... John... in this case that
ENVIRONMENTAL VARIABLE is ANSWER. One hitch is that each and every time you
run the program ANSWER.COM as shown above in sample.bat, the ANSWER
ENVIRONMENTAL VARIABLE is reset. You can store the value of answer in
another ENVIRONMENTAL VARIABLE of your choice using the SET command, to
alleviate this problem. For example, the sample2.bat file shown below
accomplishes the same task as sample.bat shown above, but reassigns the
value of ANSWER to a new ENVIRONMENTAL VARIABLE called NAME:

echo off
answer What is your name?
set name=%answer%
cls
echo Your name is %name%

The result will be the same. Now there are two ENVIRONMENTAL VARIABLES with
the same value... both NAME and ANSWER are equal to... John. The value of
an ENVIRONMENTAL VARIABLE can be cleared from memory with the following
command:

set variable=

where the word variable is the ENVIRONMENTAL VARIABLE in question... in our
examples... NAME and ANSWER. When the value of an ENVIRONMENTAL VARIABLE is
no longer needed, the command shown above should be used to free up
available memory allocated to the ENVIRONMENT.

Notice that in the examples shown above that when the value of the
ENVIRONMENTAL VARIABLE is to be used, the VARIABLENAME (i.e. NAME or
ANSWER) must be enclosed with % symbols. This is how DOS distinguishes
ENVIRONMENTAL VARIABLES from normal text.

As a more extensive example, examine the following batch file:

WORDPRO.BAT

echo off
cls
c:
cd\wp
echo Entering WordPerfect...
answer What drive contains your document?
set wpdrive=%answer%
cls
answer What subdirectory?
set wppath=%answer%
cls
answer What is the name of your document?
set document=%answer%
if exist %wpdrive%:\%wppath%\%document% goto doit
cls
echo The directory %wppath% or the document %document% does not exist!
echo Please try again!
goto fini
:doit
wp %wpdrive%:\%wppath%\%document%
set wpdrive=
set wppath=
set document=
set answer=
:fini
cd\

WORDPRO.BAT prompts the user for the name of the drive, subdirectory, and
document to be edited by WordPerfect and sets each of the values of the
WPDRIVE, WPPATH AND DOCUMENT ENVIRONMENTAL VARIABLES to the value set to
ANSWER, respectively. It then checks for the existence of this document and
if it exists it passes these ENVIRONMENTAL VARIABLES as parameters to the
command line containing the wp command. If the document does not exist,
WORDPRO.BAT informs the user and kicks him out to the end of the batch
file. When WordPerfect is exited, WORDPRO.BAT clears the values of the
ENVIRONMENTAL VARIABLES and changes the directory back to the root
directory. Believe it or not, I employ these types of batch files everyday
in systems operated by DOS novices. No complaints. I am sure you can devise
many ways to use such ENVIRONMENTAL VARIABLES and in forthcoming BATHINTS
you will see ANSWER.COM used often.

****************************************************** David Creaseyhat was copied into the RAM disk. Now whenever a program needs
to access command.com it will always be found... in the RAM disk (until you
turn off your cpu). Place these commands near the top of your config.sys
and autoexec.bat files.

The third line in your autoexec.bat file should SET the value of the PATH
ENVIRONMENTAL VARIABLE. Either of the two command lines shown below will
SET your PATH to the indicated value:

set path=d:\;c:\bat;c:\dos;c:\util or
path=d:\;c:\bat;c:\dos;c:\util

Use of the SET command is not necessary for either the PATH or PROMPT
ENVIRONMENTAL VARIABLES.

A fantastic little program written by Frank Schweiger is ANSWER.COM. This
program and its documentation have been bundled with several other useful
programs in the BATPOWER CONFERENCE file BATPOWER.ARC. When used in a batch
file, ANS