Chapter 11. Controlling Your Environment

Changing DOS Variables

The SET command enables you to adjust the DOS environment by changing the variables that are available to programs running under DOS. This command shows the current settings in the environment, or you can use the command to add or change environment variables.

Issuing the SET Command

The syntax for the SET command is as follows:

SET name=string

The variable name= is the name of the environment variable. The most frequently used environment variables are COMSPEC, PROMPT, and PATH. You can choose your own variable names in addition to these three, however. Many of the programs that you might use set their own environment variables, or require you to do so, before the program runs. These variables control the way the program works.

The parameter string is the value to which you want to set the variable. In the case of PATH, the string can be the list of directories through which you want DOS to search to find program files. If you use the name= parameter without a value for string, the variable specified is a null value (contains nothing). Using the name= parameter this way effectively removes the environment variable, and DOS no longer keeps track of it.

You also can type SET at the command prompt without any variables. The command then lists all the current settings for environment variables.

Changing Environment Variables with SET

Typically, you use the SET command as part of a batch file to set variables to be used within your system. Most often, SET is part of the AUTOEXEC.BAT file, used to set the environment variables before any other programs are run.

If you examine your AUTOEXEC.BAT file, you might see some command lines similar to the following:

SET COMSPEC=C:SYSCOMMAND.COM
PROMPT=$p$g
PATH=C:;C:DOS;C:SYS;

These commands, even though they look a bit different from each other, accomplish the same thing: They assign values to system variables. The first command tells DOS that the command processor, COMMAND.COM, is in the SYS subdirectory of drive C. The second command sets the prompt to include the current path and a greater-than sign. The third command defines the root directory, DOS directory, and SYS directory of drive C as the search path for DOS to use.

Notice that the second and third command lines do not explicitly include the SET command. It's not included here because neither of these variables requires the SET command, although you can just as easily use these command lines:

SET PROMPT=$p$g
SET PATH=C:;C:DOS;C:SYS;

Defining Your Own Environmental Variables with SET

You also can use the SET command to set custom variables in the environment. These variables usually are the names of directories or switches that programs use. The programs know to look for particular variables in the environment, take the values assigned to those variables, and use them in the program.

A word processing program, for example, might look for a dictionary file called DICT in the current directory. If you use the SET command, however, a different directory can contain the dictionary file. During installation, the program probably will insert a SET command in the batch file that invokes the program. This command can use the following form:

SET DICT=C:WPDICT

This command enables the program to look in the WP directory for the dictionary file instead of looking in the current directory. Setting a variable in the environment, however, is useful only to programs that know to look for that variable.

Tip

Each variable stored in the environment occupies space. If a program needs large variables set, you might have to increase the area of memory set aside for the environment when DOS boots. You make this change through the SHELL command in CONFIG.SYS (see Chapter 19, “Configuring Your Computer”).

Changing the User Interface

User interface is a term that is often overused in computer circles. It does describe an integral part of computers, however—how you (the user) interact with the computer. DOS provides what has come to be known as a text-based user interface, meaning that you communicate with DOS via a command line. In Chapter 4, “Using the DOS Shell,” you learned about the DOS Shell, which provides a different user interface.

If you don't want to use the DOS Shell, you can still modify how you interact with DOS. Primarily, you do so through two commands: PROMPT and MODE. The PROMPT command enables you to change what the DOS command prompt looks like, and the MODE command enables you to define how your system should work in conjunction with your video display.

Changing the Command Prompt with PROMPT

If you have ever booted a plain-vanillaversion of DOS (one that does not have a CONFIG.SYS or AUTOEXEC.BAT file), you probably noticed the default command prompt used by DOS. It looks like this:

C>

This default command prompt shows the current drive and a greater-than sign—that's it. You can, however, create a command prompt that is much more useful. You do so by using the PROMPT command. If you look at your AUTOEXEC.BAT file, for example, you might see a line that looks like this:

PROMPT $p$g

This line changes the default command-line prompt to the following:

C:>

Although this prompt might not look immediately more useful, its value becomes apparent if you switch to another directory on your drive. If you use the CD command, for example, to switch to the DOS subdirectory, your command prompt looks like this:

C:>cddos
C:DOS>

It now shows the directory where you are located. This display is of great value whenever you are issuing commands at the DOS prompt. If you use a hard disk, this display is the minimum recommended prompt setting because navigating subdirectories can be difficult if you don't know your current position. For this reason, you will find this use of the PROMPT command in many people's AUTOEXEC.BAT files.

The PROMPT command has many more settings that you can use to further refine your DOS prompt. Used to its fullest, the PROMPT command requires use of the ANSI.SYS device driver (see Chapter 17, “Understanding ANSI.SYS”). Even without using the ANSI.SYS device driver, however, you can choose from many different command prompts.

Issuing the PROMPT Command

The syntax for the PROMPT command is simple:

PROMPT string

The string consists of text that defines how you want the command prompt to appear. This text can contain special pairs of characters, called meta-strings, which consist of a dollar sign followed by one of the following characters:

b    d    e    g    h    l    n    p    q    t    v    $

The string can contain any text or any number of meta-strings in any order. Table 11.1 lists the meaning of the different meta-strings.

Table 11.1. Meta-Strings for Use with the PROMPT Command

Meta-String Displayed Information or Result
$_ Carriage return/line feed (moves the cursor to the beginning of the next line)
$b Vertical bar character (|)
$d Date
$e Esc character
$g Greater-than sign (>)
$h Backspace (moves the cursor one space to the left)
$l Less-than sign (<)
$n Current drive
$p Current path
$q Equal sign (=)
$t Time
$v DOS version
$$ Dollar sign

Tip

If you don't like the current prompt and you want to reset it to the default originally used by DOS, you can enter the PROMPT command without any parameters. This command causes DOS to reset the prompt to the current drive letter and a greater-than sign.

Understanding the Use of Meta-Strings

Earlier in this chapter, you saw an example of how to use meta-strings in a PROMPT command:

PROMPT $p$g

This is just one possible use, albeit the most often used. You also can use other combinations, such as

PROMPT Date: $d Time: $t$_$p$g

After you issue this command, your command prompt appears as follows:

Date: Thu 03-22-2001 Time: 2:35:07.23
C:WPMEMOS>

Notice that this command creates a two-line command prompt which shows the current date and time, as well as the current directory. You can get as exotic as you want with your command prompt; its appearance is entirely up to you.

Changing the command prompt based on certain configurations you might have within your system is not uncommon. Suppose that you use several different DOS programs, each of which requires its own special setup. You can create a batch file (see Chapter 16, “Understanding Batch Files”) that sets up the search paths and system variables necessary for properly using the program. If the name of this program is XYZ Spreadsheet, version 3.7, you might want to add the following line to the batch file that performs the configuration:

PROMPT Now using XYZ Spreadsheet, version 3.7$_$p$p

When this batch file executes, the command prompt becomes the following:

Now using XYZ Spreadsheet, version 3.7
C:SSDATA>

Now you can easily remember what configuration is active within your system. When you run another batch file to change the configuration again, a different prompt command that you have set up can indicate which configuration is in effect. Again, how you set up your command prompt is up to you and how you use your system.

Two of the meta-strings might require further explanation. You use the Esc character ($e) in association with the ANSI.SYS driver (see Chapter 17 for more information). In the same way that you use the dollar sign to indicate to DOS that the next character is a meta-string, you use the Esc character to signal ANSI.SYS that the next few characters are an ANSI.SYS command.

You can :use the Backspace character ($h) to remove characters from the prompt. In the earlier PROMPT example that displayed the date and time, you might find the seconds and hundredths of a second in the displayed prompt are more of a distraction than they are helpful. You can alter the PROMPT command as follows:

PROMPT Date: $d Time: $t$h$h$h$h$h$h$_$p$g

The result is the following improved prompt, with everything after the minutes erased:

Date: Thu 03-22-2001 Time: 2:35
C:WPMEMOS>

Altering the Look of the Screen with mode

You can use the external MODE command to customize the number of characters per line and the number of lines displayed onscreen. You also can use the MODE command to set the configuration of your computer ports (such as your printer port) and for code page switching.

Note

Certain areas of memory in your system store the character tables for your video screen and your keyboard. By switching tables, you can configure DOS to use alternative character sets to suit your national language and customs. These tables are called code pages. For more information about code pages, see Chapter 14, “Understanding the International Features of DOS.”

You might already know this fact, but it is possible to attach two types of video displays to your computer. You can use a monochrome adapter and display for your word processing, for example, and a color graphics adapter and display for a graphics program. You can switch between the displays by using the MODE command. When you type at the keyboard on a two-display system, you see the keystrokes only on one of the displays—the active display. The keyboard and active display make up the console. As you learned in Chapter 5, “Understanding Files and Directories,” DOS uses CON as the device name for the console.

Selecting the Display Type

To change display characteristics, you can use two forms of the MODE command (listed in Table 11.2). The following is the simplest form:

MODE dt

The abbreviation dt is the display type and mode. Available options are 40, 80, BW40, BW80, CO40, CO80, or MONO, as detailed in Table 11.2. The 40 and 80 refer to the number of text columns displayed. This setting means that you can choose between 40 and 80 characters per line. BW stands for black and white, CO stands for color, and MONO refers to the monochrome display adapter.

Table 11.2. MODE Settings for Display Type

Command Meaning
MODE 40 Sets the display to 40 characters per line
MODE 80 Sets the display to 80 characters per line
MODE BW40 Selects the color display in black-and-white mode, 40 characters per line
MODE BW80 Selects the color display in black-and-white mode, 80 characters per line
MODE CO40 Selects the color display, 40 characters per line
MODE CO80 Selects the color display, 80 characters per line
MODE MONO Selects the monochrome display

Shifting the Screen on a Color Graphics Adapter

The second form of the MODE command is for use on a Color Graphics Adapter (CGA) only. This form, which does not work on an Enhanced Graphics Adapter (EGA) or a Video Graphics Array (VGA), enables you to configure your PC to work with a television instead of a specially designed computer monitor. It moves the horizontal position of the image on your screen. If you cannot see the far-left or far-right character onscreen, the following command corrects the problem:

MODE dt,dir,T

The dt parameter is the display type described in the preceding section. The dir parameter can have the value R to move the image to the right or L to move the image to the left. If the display is in 80-column mode, MODE moves the image two characters to the right or left. If in 40-column mode, MODE moves the image one character to the right or left.

The optional T parameter, when used, causes MODE to display a test pattern that you can use to align the display. Say you type the following:

MODE CO80,R,T

A line of 80 characters appears across the screen, along with the following prompt:

Do you see the leftmost 0? (y/n)

If you respond N to the prompt, this image moves two positions to the right of its preceding position. If you respond Y to the prompt, the test is completed and the prompt is erased. Using the L option works in the same manner but moves the image to the left.

If you operate your system after shifting the screen, you have a little less memory available for your use. To display the image in an adjusted position, DOS leaves a small portion of the MODE command in memory, occupying about 1KB of memory. This program intercepts all output, adjusts it, and then sends it to the screen.

Using MODE to Adjust the Number of Columns or Lines Onscreen

You also can use MODE to adjust the number of columns or number of lines displayed onscreen. You must install the ANSI.SYS device driver before MODE can adjust your screen, however.

One way you can use MODE to adjust screen size is the following:

MODE CON COLS=a LINES=b

COLS= sets the number of columns displayed onscreen to a, and LINES= sets the number of lines displayed onscreen to b. If you omit a setting for the number of columns or number of lines, the current setting is preserved.

Valid numbers for a are 40 or 80. Valid numbers for b on a VGA screen are 25, 43, or 50; valid numbers for b on an EGA screen are 25 or 43.

If ANSI.SYS is loaded via the CONFIG.SYS file, typing the following command gives you a display mode 80 columns wide and 43 lines high on a computer with an EGA or VGA adapter and monitor:

MODE CON COLS=80 LINES=43

After you set the display mode, you can start your application program. The display mode remains, unless the application resets it. If you use the preceding MODE command on a computer with an EGA screen, for example, you can use WordPerfect in 43-line mode without adjusting any settings in WordPerfect.

Note

Not all applications can “see” that the extra lines are available. Try some MODE CON commands to determine whether you can use the extra lines. Using MODE CON to set your screen to 43 or 50 lines makes it easier to view long DIR listings, but the type is very small and can be difficult to read.

Another MODE command option enables you to alter the number of lines displayed without specifying that the screen is the console. This form, which is really a variation on the MODE CON format, is handy when you use an auxiliary console instead of CON. Chapter 13, “Controlling Devices,” introduces the CTTY command, which establishes another device as the standard input-and-output device. The syntax for this form of the MODE command is as follows:

MODE dt,b

In this syntax, dt is the display type, and b is the number of lines to be displayed. The acceptable values for dt and b are as previously described, but not all combinations of values for dt and b are possible. For example, you cannot adjust the number of lines on a monochrome or CGA monitor. Table 11.3 lists the workable combinations of parameters with the MODE command for setting the display type.

Table 11.3. Setting the Number of Lines by Display Type

Mode Option MDA CGA EGA VGA
CO40,25  4 4 4
CO40,43   4 4
CO40,50    4
CO80,25  4 4 4
CO80,43   4 4
CO80,50    4
BW40,25  4 4 4
BW40,43   4 4
BW40,50    4
BW80,25  4 4 4
BW80,43   4 4
BW80,50    4
MONO 4    

Using the information in Table 11.3, you can determine that on a VGA system you can alter the display type to color with 40 columns and 50 lines by typing the following command:

MODE CO40,50

All forms of the MODE command that adjust the display are similar in syntax and purpose. An incorrect command does not damage anything, and DOS provides reasonably clear error messages. If the ANSI.SYS driver is required and not installed, for example, DOS displays the following error message:

ANSI.SYS must be installed to perform requested function

Changing Disk Drives

As you configure DOS to the environment you need, you might find times when you need to adjust how DOS treats your disk drives and directories. Three commands enable you to do just that. You use the ASSIGN command to redirect disk requests to different drives, the JOIN command to treat a disk drive as a subdirectory, and the SUBST command to treat a subdirectory as a disk drive.

The ASSIGN Command

You use the external command ASSIGN to redirect all DOS read-and-write (input-and-output) requests from one drive to another. Each drive is a DOS device. When you use the ASSIGN command, DOS can interrogate a different disk from the one actually specified on a command line.

Warning

The FORMAT and DISKCOPY commands ignore any drive ASSIGN commands.

The syntax for the ASSIGN command is as follows:

ASSIGN d1=d2 .../STATUS

d1 is the drive letter for the original disk drive; d2 is the drive letter for the reassignment. The ellipsis (...) indicates that you can reassign more than one drive on a single command line.

/STATUS, issued with no other parameters, displays a listing of current drive assignments

The JOIN Command

You can use the JOIN command to add a disk drive to the directory structure of another disk. The external command JOIN, for example, enables you to use a floppy disk in such a way that it appears to DOS to be part of a hard disk. You also can use JOIN if you have two hard disks: drive C and drive D. JOIN can attach drive D to a subdirectory on drive C, for instance.

The syntax for JOIN is as follows:

JOIN d1: d2:path /D

The directory structure of disk d1 is added to the directory structure of hard disk d2. d1: is a valid disk drive name that becomes the alias or nickname. d1: might be a nonexistent disk drive. d2:path is the valid disk drive name and directory path that will be nicknamed d1:. If you use the /D switch, the alias is deleted.

When you use the JOIN command, DOS redirects any access from d2:path to d1:. Thus, if you use the command

JOIN A: C:SSDATA

any time you access C:SSDATA, you actually are accessing drive A. This capability is helpful if you have a program that can look only in a specific directory for data and you actually want to keep the data elsewhere.

The SUBST Command

The external command SUBST is the inverse of the JOIN command. Instead of grafting a second disk onto the tree structure of your hard drive, the SUBST command splits a disk's directory structure in two. In effect, the SUBST command creates an alias disk drive name for a subdirectory.

Issuing the SUBST Command

You can use the SUBST command to perform different functions. To establish an alias, use the following syntax:

SUBST d1: d2:pathname

To delete an alias, use this form:

SUBST d1: /D

To see the current aliases, use the following form:

SUBST

The SUBST command replaces a pathname for a subdirectory with a drive letter. After a SUBST command is in effect, DOS translates all I/O (input/output) requests to a particular drive letter back to the correct pathname. The alias drive created by the SUBST command inherits the directory tree structure of the subdirectory reassigned to a drive letter.

Note

As the default, DOS assigns the LASTDRIVE= parameter (used in CONFIG.SYS) a value of E. You can make higher drive designators, however, by inserting a LASTDRIVE= parameter into the CONFIG.SYS file. DOS then establishes as DOS devices each of the drive letters up to and including the specified LASTDRIVE. When you use the SUBST command, DOS understands that you are referring to a device.

Using SUBST to Reference a Path with a Drive Letter

SUBST is commonly used in two different situations. If you want to run a program that does not support pathnames, you can use the SUBST command to assign a drive letter to a directory. The program then refers to the drive letter, and DOS translates the request into a path. If, for example, the data for a program is stored in C:WORDPROC, you can use the following command so that you can refer to this subdirectory as drive E:

SUBST E: C:WORDPROC

After the substitution is made, you can issue the following command:

SUBST

The following message appears:

E: => C:WORDPROC

To disconnect the substitution of drive E for the C:WORDPROC directory, type the following command:

SUBST E: /D

The other use for SUBST is to reduce typing long pathnames. When more than one person uses a PC, pathnames can become quite long because each user can use a separate section of the hard disk to store data files and common areas of the disk to store programs. If the paths USER1WORDDATA and USER1SSDATA exist on drive C, for example, you can reduce the typing required to reach files in the directories by using the following command:

SUBST E: C:USER1

Issuing a directory command on drive E produces the following listing:

Volume in drive E is HARD DISK C
Volume Serial Number is 1573-0241
Directory of  E:


.            <DIR>     05-02-92  12:07p
..           <DIR>     05-02-92  12:07p
WORDDATA     <DIR>     05-02-92   1:59p
SSDATA     <DIR>     05-22-01   2:08p
        4 File(s)          0 bytes
                     3477824 bytes free

The volume label given is the label from drive C, but the directory itself contains the contents of C:USER1.

Note

Do not use the following DOS commands in conjunction with drives that you create with the SUBST command: ASSIGN, BACKUP, CHKDSK, DEFRAG, DISKCOMP, DISKCOPY, FDISK, FORMAT, LABEL, MIRROR, RECOVER, RESTORE, SCANFIX, and SYS. Some of these commands might refuse to work, and others might provide unwanted results.

As with JOIN and ASSIGN, you can use the SUBST command to fool software that insists on using an otherwise unusable drive. A friend might have written an applications program, for example, that makes direct reference in its code to a directory on drive C. By using SUBST, you can have your friend's program attach drive D to a subdirectory on your drive C.

Understanding the General Rules for Using SUBST

As you are using the SUBST command, you must keep the following rules in mind:

  • d1: and d2: must be different.

  • You cannot specify a networked drive as d1: or d2:.

  • d1: cannot be the current drive.

  • d1: must have a designator less than the value in the LASTDRIVE statement of CONFIG.SYS. (See Chapter 19 for more information on CONFIG.SYS.)

  • Do not use SUBST with ASSIGN or JOIN.

  • Remove all SUBST settings before you run ASSIGN, BACKUP, DEFRAG, DISKCOMP, DISKCOPY, FDISK, FORMAT, LABEL, MIRROR, PRINT, RECOVER, RESTORE, SCANFIX, or SYS.

  • Beware of using APPEND, CHDIR, MKDIR, PATH, and RMDIR with any drives reassigned.

Using the COMSPEC Variable

COMSPEC is a reserved system variable name that defines your command processor's location. Typically, it is set to the complete path and filename for COMMAND.COM. If your command processor is not in the root directory of the boot drive, you must include an appropriate SHELL directive in CONFIG.SYS to inform DOS of the command processor's location. This command, in turn, automatically sets the COMSPEC variable correctly. Thus, you don't need to explicitly set the COMSPEC variable in your AUTOEXEC.BAT file if you use the SHELL directive. If you do not have the COMSPEC variable set on your system, your system might hang when you boot your computer or when you leave an application program that needs to reload the command processor. This failure occurs because the system cannot find the command processor. Refer to Chapter 19 for information on how to use the SHELL directive in CONFIG.SYS to tell the system where to find the command processor.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.93.169