Chapter 13. Controlling Devices

Device Commands

Devices—hard disks, printers, video displays, keyboards, and modems, for example—can supply input to the computer, receive output from the computer, or both. This chapter discusses the commands that control the devices connected to your computer. You use these commands to redirect input and output, select alternative keyboards, and print graphics and text files.

DOS supplies many different commands to help you interact with devices. With three commands referred to as filters, DOS is responsible for channeling information between devices. You can use these filters—MORE, FIND, and SORT—to modify information as it passes from files to the screen. Table 13.1 lists and explains the functions of the commands and filters discussed in this chapter.

Table 13.1. Device Control Commands and Filters

Command Function
CLS Clears the screen
GRAPHICS Prints graphics screens
PRINT Prints in the background
CTTY Selects a different console; makes the serial port the console
MODE Controls device operations; redirects a parallel port to a serial port; changes the typematic rate
MORE Filter to control the display of text
FIND Filter to find strings of text
SORT Filter to sort information

Table 13.2 lists and explains the functions of the redirection operators you use in conjunction with the device control commands and filters.

Table 13.2. Redirection Operators

Operators Function
< Redirects a command's input
> Redirects a command's output
>> Redirects a command's output and appends the output to the target, if one exists
| Passes the output from one command to another as input

The CLS Command

The internal command CLS clears the screen, removing all visible text. CLS then displays the prompt so that you can continue to issue DOS commands. This command clears only the onscreen display. If your system uses two screens, CLS clears only the active display, not both screens.

The CLS command, which has no switches, uses the following syntax:

CLS

Clearing the screen does not change the display mode. If, for example, you used the MODE command to change your screen display to 40 columns, the screen is cleared when you issue the CLS command; CLS then redisplays the DOS prompt in 40-column mode. All other attributes that you set previously—for example, if you defined a background color and foreground color by using ANSI.SYS escape sequences—are also retained.

Tip

You can frequently use the CLS command in batch files. By inserting a CLS command at the end of the AUTOEXEC.BAT file, for instance, you can remove all the messages that memory-resident programs might display as they load into your system.

The GRAPHICS Command

You might have tried to use the Print Screen key (PrtSc on some keyboards) to print the contents of your screen to a printer. If so, you might have discovered that this key works properly only when your screen is in text mode.

If your monitor is a CGA, EGA, or VGA display, the external command GRAPHICS enables you to use the Print Screen key to print graphics screens, also. When you execute GRAPHICS, a portion of the program remains memory-resident. When you next press Print Screen, all ASCII code characters that would otherwise print as text are converted to graphics before the information is sent to the printer.

Issuing the GRAPHICS Command

Use the following syntax for the GRAPHICS command:

GRAPHICS printer [drive]:pathfilename /R /B /LCD /PRINTBOX:STD

printer is the type of printer you are using. Table 13.3 lists the values you can use for the printer parameter. If your printer is not listed, it might be compatible with one of the other printers on the list. Refer to your printer's instruction manual for details. If you do not specify a printer, DOS assumes the GRAPHICS printer type.

Table 13.3. Printer Types and Settings

Printer Type Model Name
COLOR1 IBM PC Color Printer with black ribbon, which prints in grayscale
COLOR4 IBM PC Color Printer with RGB (red, green, blue) ribbon, which prints four colors (RGB plus black)
COLOR8 IBM PC Color Printer with CMYK (cyan, magenta, yellow, and black) ribbon, which prints eight colors
DESKJET Hewlett-Packard DeskJet printer
GRAPHICS IBM Personal Graphics Printer, IBM ProPrinter, or IBM Quietwriter printer
GRAPHICSWIDE IBM Personal Graphics Printer with an 11-inch carriage, or IBM ProPrinters II and III
HPDEFAULT Any Hewlett-Packard PCL printer
LASERJET Hewlett-Packard LaserJet
LASERJETII Hewlett-Packard LaserJet II
PAINTJET Hewlett-Packard PaintJet printer
QUIETJET Hewlett-Packard QuietJet printer
QUIETJETPLUS Hewlett-Packard QuietJet Plus printer
RUGGEDWRITER Hewlett-Packard RuggedWriter printer
RUGGEDWRITERWIDE Hewlett-Packard RuggedWriter wide printer
THERMAL IBM PC-Convertible thermal printer
THINKJET Hewlett-Packard ThinkJet printer

[drive]:pathfilename is the drive, path, and filename of a printer profile file that can be used by the GRAPHICS command for your printer. This file supports the printers of other manufacturers. If your printer doesn't fit into one of the categories supported by GRAPHICS, you can create a custom printer profile for use with GRAPHICS. The filename parameter refers to the profile file, which specifies how graphics are translated for various printers. The profile file is an ASCII text file with two types of information for each printer in the file. A profile can include information about how the printer is controlled, such as selecting printer colors or adjusting the darkness of the printed piece. The second section of the profile lists the translation from the screen to the printer.

/R forces the printer to print a monochrome text screen as you see it—black background and white text. When you use the /R switch with a color screen, the darkest colors (black or blue) print as black, light colors appear as white or light gray, and other colors print as different shades of gray on a grayscale for contrast. If you don't use the /R switch, all onscreen information that is white prints as black, and all black onscreen information (usually the background) prints as white. The paper color in the printer is assumed to be white.

/B prints the background color. Use this switch only if you have a color printer and after you specify COLOR4 or COLOR8 as your printer type. If you try to use the /B switch with a black-and-white printer, DOS displays the following message:

The /B switch is invalid with black and white printers.

/LCD is a switch designed for use with the IBM PC-Convertible, which comes with a small liquid-crystal display (LCD) screen. /LCD forces the printer to print the screen as it appears, with the size of the screen and characters smaller than on normal monitors. You also can use this switch with any other laptop computer that has an old-style, smaller LCD screen like the IBM PC-Convertible. Most laptops now have a full-sized LCD screen and don't require the use of this switch.

/PRINTBOX:STD sets the printbox size to standard or normal size, as it appears on monochrome and VGA monitors of standard size and shape. You use this setting to print the screen when you work with Quattro Pro, Microsoft Word, or other programs in graphics mode. You also use this setting to print the contents of a narrow LCD screen if you want it to appear as if it were on a standard monitor. By typing /PRINTBOX:LCD, you can use this switch to force the printer to print in LCD mode (a longer form of the /LCD switch, shown earlier). You can abbreviate the /PRINTBOX switch to /PB.

Using GRAPHICS to Print a Screen Image

Suppose that you have an IBM ProPrinter printer. If you use a monochrome system and want to print a screen image with the background as black and the text as white, enter the following command at the DOS prompt:

GRAPHICS /R

After GRAPHICS loads into memory, you can create the screen of interest and press Print Screen to print to the printer.

To print eight-color images (including the background color) on an IBM PC Color Printer with a CMY ribbon installed, type the following command:

GRAPHICS COLOR8 /B

On the PC-Convertible with an attached full-sized monitor, you can send the screen image to the IBM PC-Convertible thermal printer by typing the following:

GRAPHICS THERMAL /PB:STD

Changing the command to either of the following prints the image as it normally appears on the liquid-crystal display:

GRAPHICS THERMAL /PB:LCD
GRAPHICS THERMAL /LCD

You should remember the following guidelines when using the GRAPHICS command:

  • After you load GRAPHICS, you can press the Print Screen (Shift+PrtSc) key to print graphics screens on listed graphics printers.

  • If you omit the /PB and /LCD switches, GRAPHICS uses the previous printbox setting.

  • You can print up to eight colors on a color printer.

  • You can print up to 19 shades of gray on a black-and-white printer.

The PRINT Command

In Chapter 8, ”Managing Your Files.,” you learned that the COPY command can transfer information from one device to another. For example, this command copies the file named LETTER.TXT to the device PRN, the printer:

COPY LETTER.TXT PRN

During this copying process, the computer is not available for other use. Copying a large file to the printer can tie up your computer for a great while, depending on the speed of your printer.

You can make better use of your computer if you use the PRINT command. This command enables you to print in the background, thereby freeing up your computer for other tasks while you print a document. Printing occurs during the idle times—while the computer is waiting for you to type at the keyboard, for example. You also can queue files, which means send multiple files to the printer, each of which then prints in turn.

Issuing the PRINT Command

The external PRINT command uses the following syntax:

PRINT <switches> filename1 /P /T /C filename2 /P /T /C...

You can replace <switches> with any of the switches listed in Table 13.4. filename1 is the drive, path, and filename of the first file you want to print, and filename2 is the drive, path, and filename of the next file you want to print. The ellipsis (…) means that you can list more files. You also can use wildcards in the filenames.

Table 13.4. Switches for the PRINT Command

SwitchMeaning
/D:device Names the serial or parallel port to which your output device is attached. Acceptable values include all DOS output devices and ports, such as LPT1, LPT2, LPT3, PRN, COM1, COM2, COM3, COM4, or AUX.
/Q:qsize Specifies the maximum number of files—from 4 to 32—that can be queued at a time. If you omit the switch, the default queue size is 10 files.
/B:size Determines the size of buffer used in the printing process. The data for printing is taken from the disk in chunks the size of the specified buffer. Increasing the buffer size causes the PRINT command to read data from the disk in bigger chunks. The minimum buffer size is 512 bytes; the maximum is 16KB. If you don't specify the buffer size, the default size is 512 bytes. Remember that the larger you make the buffer, the less RAM you have for running applications programs.
/U:ticks1 Determines how long (in system clock ticks) the PRINT command waits for the printer to be available. In most cases, the PRINT command sends data to the printer faster than the printer can actually print. When the printer cannot accept any more data, it sends a busy signal to the computer until it is ready to accept more data. The default setting for /U:ticks1 is 1 clock tick, but you can set it as high as 255. If the printer is busy, PRINT waits the number of clock ticks set by this switch. If the printer is still busy, PRINT immediately transfers control back to DOS for other tasks without using the rest of the clock ticks set aside for it by the /S:ticks3 switch.
/M:ticks2 Specifies the number of system clock ticks that the PRINT command waits for the printer to print a character. You can set ticks2 to any value between 1 and 255; the default value is 2.
/S:ticks3 Determines the number of clock ticks allocated to background printing. Too high a value for this switch causes the computer to respond sluggishly to other commands that you execute while you print in the background. A low value slows the printing process. The range of values is 1 to 255; the default value is 8.

Like GRAPHICS, PRINT leaves a portion of itself in memory after you issue the command, and the switches change how the PRINT command works. You can specify the optional switches in Table 13.4 only when you first issue the PRINT command. The other switches (issued after the filenames) can be issued at any time, however:

  • The /P switch places a file in PRINT's queue. The preceding file and all subsequent files on the command line are printed.

  • The /C switch cancels the printing of some files. The filename issued before the /C and all files after the /C on the same command line are removed from the print queue. (The printer alarm sounds if you cancel the currently printing file with the /C switch.) You must issue the /P switch to add files to the queue again.

  • The /T switch terminates printing. All files are removed from the queue, including the file being printed. The printer alarm sounds, a file cancellation message prints, and the paper advances to the next page.

If you enter filenames without a /P, /C, or /T switch, DOS uses the /P switch as a default so that all files are placed in the queue for printing. If, at the prompt, you type PRINT with no switches, a list of all files in the queue appears. This list includes the name of the file that is currently printing and the order of files yet to print. This command also displays any error messages. If, for example, you forget to turn on the printer, the following error message appears:

Errors on list device indicate that it may be off-line. Please check it.

Using PRINT to Print Several Files

You do not have to enter the names of all the files to print at one time. You can issue the PRINT command several times to add or remove files from the print queue. You can specify the parameters that affect the way PRINT operates (those in Table 13.4), however, only when you first issue the command. After you first issue the PRINT command, you use the command only to enter filenames for printing or to cancel printing.

If you enter the PRINT command for the first time without specifying a device, PRINT prompts you for a device name. The default, PRN, is the first parallel port (LPT1) on your computer. Pressing Enter at the DOS prompt accepts the default.

If you are in no hurry to collect the printed output of files and want to use the computer while the printer prints your files, you can readjust the default installation settings for PRINT. By changing the /M:ticks2 or /S:ticks3 settings, you can give your computer better response time. To alter the default settings, you can type the following when you invoke the PRINT command for the first time:

PRINT /D:PRN /M:1 /S:25

If you are unconcerned about the sluggishness of the keyboard, you can improve the speed of the background printing by altering the buffer size, as well as by adjusting /M:ticks2 and /S:ticks3. You might type the following command, for example:

PRINT /D:PRN /B:16384 /M:1 /S:25

Experiment with these variables until you find a setting that is acceptable. A sluggish keyboard is not always tolerable. If the response time is too slow, you can make errors; for example, you might assume that a program didn't accept your keystrokes and try to retype the command, whereas the program was only waiting to regain control.

By using a combination of the /P, /T, and /C switches, you can adjust the order in which the files print. Suppose, for example, that you want to print four files: LETTER1.TXT, MEMO1.TXT, REPORT1.TXT, and REPORT2.TXT. Type the following on the command line:

PRINT /D:PRN LETTER1.TXT /P MEMO1.TXT REPORT1.TXT REPORT2.TXT

If you then decide that you want to print REPORT2.TXT before REPORT1.TXT, type the following command, which removes REPORT1.TXT from the print queue and adds the file to the end of the queue:

PRINT REPORT1.TXT /C REPORT1.TXT /P

You can cancel all files to be printed by typing the following command:

PRINT /T

General Rules for Using PRINT

As you are using PRINT, you should keep the following guidelines in mind:

  • You can specify the /D:device, /Q:qsize, /B:size, /S:ticks3, /U:ticks1, and /M:ticks2 optional switches only the first time that you issue the PRINT command.

  • If you specify /D:device, you must type this switch first, before all other switches.

  • If you issue /P, the preceding file and all subsequent files entered on the command line by the PRINT command print until a /T or /C switch is issued.

  • If you issue /C, the preceding file and all subsequent files are canceled.

  • The files print in the order that you enter them at the command line.

  • A page-eject sequence is sent to the printer at the end of each file.

  • You cannot use the printer for other purposes while PRINT is in operation. You cannot, for example, use Print Screen when PRINT is in effect.

  • The files being printed must be on the same disk drive.

  • You cannot alter files that are in the print queue or being printed.

  • Specifying a nonexistent device causes unpredictable behavior by the computer.

  • Tab characters in the printed file convert to blanks, up to the next 8-column boundary.

Note

GRAPHICS.PRO is the profile file supplied with DOS. If you want to create a custom profile file for your printer, make a copy of the supplied GRAPHICS.PRO file and modify it. This exercise is also useful if you are interested in DOS programming. Modifying the GRAPHICS.PRO file is not necessary for most printers.

If the onscreen colors don't have a sharp enough contrast, the GRAPHICS command can “miss” the difference between colors and produce an all-white or all-black printout. If this problem occurs, try altering your screen colors before you print.

The CTTY Command

DOS can take information or data from and send it to different kinds of devices. Any device that you can use to give information to DOS is called an input device, and any device DOS can send information to is an output device. DOS uses your keyboard and screen as the standard input and output devices. Together, these two devices make up the console, known to DOS as the CON device. The internal command CTTY enables you to tell DOS that you want to use a different device for input and later enables you to restore the keyboard and screen as the console.

Use one of these syntax lines for the internal command CTTY:

CTTY device

CTTY CON

device is the name of a DOS device that you can use for input. CTTY causes DOS to intercept the input/output (I/O) requests that normally come from the keyboard and go to the screen; the command redirects these calls to the device you specify.

By typing the following command, for example, you designate COM1 as the device that sends and receives standard input and output:

CTTY COM1

You use this command in association with specialized programs that need input from a different source from the keyboard. Later, typing the following from the auxiliary device restores the console to the keyboard and display:

CTTY CON

You also can use CTTY if the computer is attached to an intelligent bar-code reader that collects information from packages. This reader, in association with a specialized program, might not need to use the display or keyboard.

You probably will not need to use the CTTY command. DOS usually can gather information through alternative devices without altering the standard input and output devices. Certain applications programs, however, benefit from your use of CTTY. One example is the DOS external program Interlnk, which requires the CTTY command in order to transfer itself to another computer.

→ For more information on the Interlnk program, see Chapter 8, “Managing Your Files.“

If you decide that you need to use CTTY, keep the following rules in mind:

  • You can use the character-based devices AUX, COM1, COM2, COM3, or COM4 as the alternative console.

  • The physical device attached to the relevant AUX, COM1, COM2, COM3, or COM4 must be able to accept input and provide output.

  • Programs that do not use DOS function calls cannot make use of the alternative console.

The MODE Command

MODE is one of the more versatile external commands supplied with DOS. It sets the operational modes of serial and parallel ports and redirects information from parallel ports to serial ports. MODE also can set display modes, and you can use MODE with code pages.

→ For more information about display modes and code pages, see Chapter 11, “Controlling Your Environment,” p. 293, and Chapter 14, “Understanding the International Features of DOS,” p. 339.

In this chapter, you learn how you can use the MODE command to control the parallel and serial ports, as well as to change how the keyboard acts. To read about all functions of the MODE command, turn to the “Command Reference” later in this book.

Using MODE to Change Parallel Port Settings

A parallel port transmits data by transferring an entire byte at one time. Because of the way data is transferred, parallel ports are typically used to send information to a printer. To help control your printer, you can use the MODE command to adjust the number of lines per inch and columns per line on your printer and to set the retry feature.

Issuing the MODE Command

Use the following syntax for the external MODE command, which changes the parallel printer characteristics:

MODE LPTn: cpl,lpi, P

LPTn: is the parallel port name, such as LPT1 or LPT2. cpl is the number of characters per line; the default cpl setting is 80. lpi is the number of lines per inch; the default setting for lpi is 6. P specifies continuous retries on timeout or “busy” errors.

MODE also enables you to use an alternative format, as follows:

MODE LPTn: COLS=wid, LINES=lpi, RETRY=action

wid is the number of columns per line, 80 or 132; lpi is the number of lines per inch, 6 or 8; and action is the message you want DOS to return or the action DOS should take when the printer port is busy.

When you use the MODE command to adjust the parallel port settings, this command alters only two items seen on the printout itself: the characters per line and lines per inch. In general, printing is performed directly from an applications program, which can set many more parameters for a particular printer. The MODE command operates by sending Escape sequences to the printer that can adjust the printed output accordingly.

The RETRY setting is more significant than the other settings. When data is sent to the printer, the port expects to see return signals from the printer indicating that it received the data. If the port doesn't receive any signals within a particular period of time, a timeout error occurs. By default, DOS does not try to send information to the printer again and returns an error message to the screen. If you include the P option, DOS continuously tries to send the data; this action prevents the error message from being displayed. Pressing the Ctrl+Break key combination stops the retry process.

If you use the RETRY switch in the alternative MODE format, various retry options are available. If you don't specify a retry option, DOS doesn't continue trying to send data when a timeout error occurs. When you use the retry option, you can select from several options. The following list explains the various options:

  • The B setting returns a busy signal to the device driver when the port is busy. This setting is not available with DOS 6.0.

  • The R setting causes a ready signal to be returned from the port—even if the port is busy. Then, when the printer does become ready, the data is ready to send, and an error message does not appear onscreen.

  • The E option is most commonly used when the printing is done in the background (by PRINT or a network print queue). The data is not transferred to the printer until the port is not busy.

  • The N setting indicates that no retry action is taken.

  • The P option causes DOS to try the printer continuously until the busy state ends.

Using MODE to Print a Large File

In some cases, you must use the P option to print a file. Consider a large DOS file that you want to copy to the printer. If the file is larger than the storage capacity of the printer, the printer port will be busy at some point during the data transfer. If the printer remains busy for too long, an error message appears onscreen; DOS thinks the printer is defective, and the printing process aborts. This outcome is a particular concern when you are printing large, complex files such as those created by a PostScript program.

Specifying P in DOS 3.3 and earlier or RETRY=B in DOS 4.0 and 5.0 causes DOS to wait until the printer is ready to receive data. (The B option is not available in DOS 6.0, but you can use the P option for this purpose.) Use the following command for LPT1 in DOS 3.3:

MODE LPT1:,,P

For DOS 4.0, 4.01, 5.0, and 6.2, use the following command:

MODE LPT1 RETRY=B

For DOS 6.0 or 6.2, use the following command:

MODE LPT1 RETRY=P

If the file is large and you want to be able to fit more lines of text on a page, you can print the file with a higher number of lines per inch (8 instead of 6). Also, you can specify 132 columns per line instead of 80. This setting is not a problem for a wide-carriage printer, which accepts wide paper. If you are using a printer that accepts 8 1/2-inch paper, however, you must set the printer to print in a condensed character mode, which can fit 132 columns on a line of 8 1/2-inch paper.

When the printer is attached to LPT2, use the following command to fit as much information as possible on a page:

MODE LPT2:132,8

General Rules for Using MODE to Change Parallel Port Settings

When you are using the MODE command to change parallel port settings, you should keep the following rules in mind:

  • The default values of the port will reset if you reset or initialize the printer.

  • If you omit a parameter from the command line, the setting for that parameter does not change.

  • Do not use any of the retry options when printers are being shared on an IBM PC network.

Using MODE to Change Serial Port Settings

You can use another option of the MODE command to alter the functions of the serial ports. This command works in a way similar to the parallel port adjustments. DOS changes the parameters that are sent to and from the device driver.

The acceptable serial ports are COM1, COM2, COM3, and COM4. The serial port can receive and transmit data only one bit at a time. The signaling rate (the number of times per second that data is transmitted) is the baud rate. The amount of data transferred in a second is referred to as the bps (bits per second).

You can use the MODE command to adjust the baud settings and change the amount of data sent in a fixed time. Although it is called a baud setting, the numbers used are actually the number of bits transmitted per second. Acceptable baud settings are 110, 150, 300, 600, 1200, 2400, 4800, 9600, and 19200. You need to use only the first two digits of the number to set the baud rate.

The most common devices attached to a serial port that you need to set from DOS are serial printers and plotters. Although modems are serial devices, you usually don't adjust them from DOS. Communications programs, however, use the DOS functions to make adjustments to the serial ports.

Use the following syntax to change the serial port:

MODE COMy: baud,parity,databits,stopbits,P

The elements of the commands are as follows:

  • COMy: is the name of the serial port device.

  • baud is the baud rate. You must specify the baud rate for the serial port.

  • parity is the parity. Parity is used in error-correction algorithms.

  • databits is the number of data bits. The default number of data bits is 7.

  • stopbits is the number of stop bits. Stop bits mark the end of a character being transmitted. The default number of stop bits is 1 for all baud rates except 110, when 2 stop bits are set as the default.

  • P specifies continuous retries on timeout errors.

You also can use the following syntax:

MODE COMy: BAUD=baud PARITY=parity DATA=databits STOP=stopbits RETRY=action

All the variables in this version of the MODE command are the same as in the previous version. The only new one is action, which is the message you want DOS to return when the port is busy.

With versions of DOS before Version 4.0, the retry feature provided two choices when a timeout error occurred: no retry or continuous retries when you included the P option. When data is sent to the printer, the port expects to see signals from the printer indicating that it received the data. If the port doesn't receive any signals within a particular period of time, a timeout error occurs. By default, DOS does not try again to send information to the printer and returns an error message to the screen. If you include the P option, DOS continuously tries to send the data; this action prevents the error message from being displayed. The Ctrl+Break key combination stops the retry process.

With DOS 4.0 and later, more retry options are available. If you do not specify a retry option, DOS doesn't try again to send data when a timeout error occurs. When you use the retry option, you can select from the following four options:

  • The R setting causes a ready signal to be returned from the port even if the port is busy. Then, when the printer does become ready, the data is ready to send, and an error message does not appear onscreen.

  • The E option is most commonly used when you are printing in the background (using PRINT or a network print queue). The data is not transferred to the printer until the port is not busy.

  • The N option specifies no action; this setting is the default.

  • The P action specifies continuous retry.

Using MODE to Set the Serial Port

To set the first serial port to communicate at 2400 bps, with 8 data bits, 1 stop bit, and no parity, you can type one of the following commands:

MODE COM1 2400,N,8,1

MODE COM1 24,N,8,1

If you are using DOS 3.3 or later, you can type the following instead to get the same settings:

MODE COM1 BAUD=24 DATA=8 STOP=1 PARITY=NONE

Note

The printer or plotter needs to be set to receive data in the same format in which the serial port is sending the data—that is, the same baud rate, parity, and so on.

General Rules for Using MODE with Serial Ports

When you are using the MODE command to change serial port settings, you should keep the following rules in mind:

  • If you set a retry option, a portion of MODE remains resident unless you use the DOS 4.0 RETRY=none option.

  • The retry option slows the performance of foreground tasks when computers are being shared on an IBM PC network.

  • DOS 4.0 and later can include Mark or Space parity settings. All versions of DOS support none, odd, and even parity settings.

Using MODE to Redirect a Parallel Port to a Serial Port

The final MODE setting you can use with ports is the command to redirect a parallel port to a serial port. Typically, you use this setting if you want to redirect printer output to the serial port for use with a plotter or serial printer.

Issuing the MODE Command to Redirect Ports

Use the following syntax for the MODE command that changes the parallel printer to a serial printer:

MODE LPTn:=COMy:

LPTn: is the name of the parallel printer port, and COMy: is the name of the serial port.

After you use MODE, DOS channels to the serial port all I/O requests that a program sends to the parallel port. The electronics associated with the port handle automatically the conversion of data from bytewide to bitwide.

Using MODE to Redirect Ports

Some early programs don't directly support serial printers. To use a serial printer, you can set a serial port and redirect a parallel port to that serial port. This process enables you to print when you use a serial printer and also use a program that doesn't directly support the printer.

Earlier in this chapter, you learned how to initialize a serial port by using the MODE command. For example, you initialize a serial port with DOS 3.3 by using a command similar to the following:

MODE COM2 2400,E,7,2

With DOS 4.0 and later, you can type the following command instead:

MODE COM2 BAUD=24 DATA=7 STOP=2 PARITY=EVEN

You then follow the initialization command by typing the following command:

MODE LPT1=COM2

All data that normally goes to LPT1 is transmitted to COM2 at 2400 bps, with 7 data bits, 2 stop bits, and even parity.

General Rules for Using MODE to Redirect Ports

When you are using the MODE command to redirect ports, you should keep the following rules in mind:

  • You can redirect any parallel port to any serial port.

  • You must initialize the serial port with both speed and data characteristics before the parallel port is redirected.

  • The initialization of the serial port must include the retry option if the attached device is a printer.

Using MODE to Change the Typematic Rate

When you press a key on the PC keyboard, a character appears onscreen. If you continue to hold down the key, the pressed character repeats onscreen. The number of times per second the key repeats is known as the typematic rate.

The syntax for the MODE command that changes the typematic rate is as follows:

MODE CON RATE=rate DELAY=delay

rate is the number of repetitions per second. The rate parameter can have values in the range 1 through 32. These values represent a repeat rate of from 2 to 30 characters per second (the higher the value, the faster the repeat rate). The default value is 20 for an IBM AT and 21 for an IBM PS/2, which is equivalent to approximately 10 characters per second.

The delay parameter is the time delay before DOS starts repeating a key. The delay is specified in .25-second intervals. The range for the delay is 1 through 4, making a total possible delay of 1 second.

To set the keyboard so that the delay before the key repeats is 0.75 second and the rate value is 24, type the following:

MODE CON RATE=24 DELAY=3

Using Redirection Commands

DOS uses three standard devices: one for input, one for output, and one for errors. The main input/output device is the console, which is DOS's name for your keyboard and screen. The keyboard is the standard input device, and the display is the standard output and error device. In short, you type commands on the keyboard, and the commands and any error messages appear onscreen.

DOS enables you to choose the devices that you use to input and output information; this process is called redirection. (Error messages are always sent to the screen.)

Issuing the Redirection Operators

The redirection symbols are the greater-than and less-than signs. If you think about it, these symbols look like arrows (> or <) that show the input's source and destination. Use the following syntax for redirecting a program or command's input:

command < inputdevice

The syntax for redirecting a program or command's output is shown in the following:

command > outputdevice

The syntax for redirecting and appending to an existing file is shown in the following:

function command >> outputdevice

In each syntax shown here, inputdevice is the source of the input, outputdevice is the destination of the output, and command can specify almost all applications programs or DOS commands. With the redirection command, you can use any DOS output device as an outputdevice, and you can use any DOS input device as an inputdevice.

Normally, redirected input comes from a file. Some devices, however, such as a mouse or bar-code reader, can also be used as a source of input. You can write a file that consists of the keystrokes used to operate a program, for example, or you can use the output from a mouse as the input for a program.

Most DOS users redirect output more often than they redirect input. The two most common places to redirect output are to the printer or to a disk file. The following command, which redirects the output of a directory to the printer, is a common example of redirection:

DIR > PRN

When you issue this command, DOS redirects the output (the directory listing itself) to the PRN device instead of sending the listing to the screen. This command produces a hard-copy listing of the directory.

Another common use is redirecting output to a file. To review the statistics of the MEM /C command, for example, type the following command:

MEM /C > CLASSIFY.MEM

When you use redirection commands with pipes and filters, discussed later in this chapter, the command becomes even more powerful.

Warning

Take care when you use the > operator to send output to a file. If you use > and refer to an existing file, DOS overwrites the existing file with the new output—without warning.

If you want to redirect to the printer a copy of your disk's directory structure and a list of the files on your hard disk, type the following:

TREE C: /F >PRN

The TREE command does not supply a directory listing that includes file sizes. If you want to create a full listing of all the directories on your hard disk by using redirection to append the output of the command, you specify that each directory be listed and then specify that the output be appended to a file. You then can print the full list. To perform this task, you type a command similar to the following for each directory:

DIR C: /S >> FULLIST.DIR

The DIR command lists the files in all the directories on drive C. The /S switch causes the DIR command to display all subdirectories. You can then substitute the names of other drives for C.

If you are testing programs that require a large amount of user input, the following redirection method is useful. For example, you can type the following:

PROGRAM < C:TESTPAT

This command results in the file TESTPAT supplying the input to PROGRAM. The redirection process enables you to construct a file that contains the correct keystrokes needed to oper-ate a program. You then can test the program's basic operation before you include the error-trapping sequences. These sequences handle the situations when the user presses an incorrect key.

General Rules for Using Redirection

The following are some helpful rules to know when using redirection:

  • Do not use redirection on a DOS batch file command line that includes CALL, FOR, or IF.

  • Using > and referring to an existing file cause DOS to overwrite the existing file with the new output.

  • Using >> adds the output to an existing file or creates a new file if the file does not exist.

The MORE Filter

DOS uses elements called filters to channel information between devices. You can use these filters to modify information as it passes from files to the screen. Filters, which work only on ASCII text files, are often used with the redirection symbols so that input can come from a source other than the keyboard or be sent to a device other than the screen.

Piping is another feature used with these commands. You use the pipe symbol (|) to send output information that normally goes to the screen as input to another program. Piping, a form of redirection, diverts information destined for a device but then makes the information become the input from a device to another program.

The MORE filter buffers information from the input device or file and sends the data to the monitor one screen at a time.

Issuing the MORE Filter

The syntax for the MORE filter, which has no switches, is shown in the following:

MORE

MORE is commonly used in the following way, where filename is the input file:

MORE < filename

Or, it is used in the following way, where command is any command or program:

command | MORE

MORE collects—and saves in a temporary disk file—information that normally goes to the screen. When a screen of input is obtained, MORE sends that information to the standard output device all at the same time. The text is channeled through the MORE filter until the end-of-file. Press any key when DOS displays the -- More -- prompt; this action displays the next screen. After all the information is displayed onscreen, DOS erases the temporary file created by MORE.

Using MORE to Pause the Screen

When you use MORE to pause directory listings, the filter serves a function similar to the /P switch that is available with the DIR command.

The most common use of MORE, however, is to pause the TYPE command. To read the contents of a README.DOC file one page at a time, for example, type one of the following:

TYPE README.DOC | MORE

MORE <README.DOC

Both syntax forms work identically. To see the contents of a file, you can use the TYPE command. If the output of the file flows off the screen, reissue the command by pressing F3, and add the pipe character (|) and MORE.

General Rules for Using MORE

The following are some helpful rules to know when using MORE:

  • Do not use MORE alone. MORE is a filter, which requires input to redirect or pipe.

  • To view additional screens full of information, press any key when DOS displays the -- More -- prompt.

  • Ctrl+Break (and Ctrl+C) terminates the command without displaying any other screens.

The FIND Filter

The FIND filter finds ASCII text in files. This filter often is used in association with redirection and piping.

Issuing the FIND Filter

Use the following syntax for the FIND filter:

FIND /C /N /V /I "string" filename...

"string" specifies the ASCII characters for which you want to search, and filename is the full filename of the file to search. The ellipsis (…) indicates that you can specify more than one file to search.

/C causes FIND to count all the lines that contain "string". You use the /C switch to count the number of lines with the ASCII string; the text itself isn't passed to the screen.

/N causes FIND to include line numbers of the lines that contain the "string". You use the /N switch to locate the line numbers within the text file. The line numbers listed are the line numbers in the original text file, not just sequential numbers. If the third, fifth, and sixth lines in the text file contain the string, for example, the line numbers displayed are 3, 5, and 6—not 1, 2, and 3.

/V causes FIND to search only for lines that do not contain the "string". Only these lines are passed on to the screen.

/I makes FIND insensitive to case: Upper- and lowercase letters are considered the same.

Note

You can use /C and /V together. The count displayed is the number of lines that do not contain "string". You also can use /V and /N together. The lines that do not contain "string" are displayed with their appropriate line numbers.

If you use FIND without options, the filter reads each of the files you specify and displays all lines that contain the ASCII string you are looking for. DOS filters the information that normally goes to the output device. All lines that include the ASCII string are displayed onscreen.

Like the other filter commands, FIND is often used with redirection and piping. If you search a text file for lines that include specific information, redirecting the output to a file might be helpful. You then can use the list as a reference while you look at the whole of the original file.

Using FIND to Find Files on Disk

You can use the FIND command to find all files that have a certain extension. To find all files with the extension .LET, for example, type the following command:

DIR /S /B | FIND ".LET"

Because the /S switch is used with this DIR command, all files whose names contain LET—either in the root or extension—are listed under the name of the directory containing them. Because the /B switch is used, the filenames are listed in the form FILENAME.EXT, with a period instead of spaces separating the filename and its extension. Therefore, you can search for .LET instead of LET. In this form, each filename is preceded by its directory path.

The DIR command with the /S option lists all the files on a disk. The output for DIR that normally goes to the screen is filtered through the FIND command. The output from FIND then is displayed onscreen.

You also can use the FIND filter with text files as a word-search utility. Suppose, for example, that you forget the name of the memo you sent to your boss, but you know that the file is either MEMO1, MEMO2, or MEMO3. You also know that you always use your boss's title, Supervisor, in memos. You can find the memo you need by typing the following:

FIND "Supervisor" MEMO1 MEMO2 MEMO3

When you issue this command, each line that contains Supervisor is listed. The listing appears in the following form:

---------- MEMO1
---------- MEMO2
Supervisor of Communications
---------- MEMO3

General Rules for Using FIND

The following aresome helpful rules to know when using FIND:

  • Use FIND only on ASCII text files.

  • The "string" parameter is normally case sensitive; that is, FIND regards the uppercase string LOOK as different from the lowercase string look. In DOS 5.0 and later, you can use the /I switch to perform a search that is not case sensitive.

  • To cause FIND to search for quotation marks in a string, type two quotation marks together (""). FIND then searches for occurrences of ".

  • If you do not specify a filename, FIND uses the standard input device.

  • You cannot use wildcards in a filename.

The SORT Filter

The third DOS filter is SORT, which sorts the information from an ASCII file before displaying the result onscreen. Like FIND and MORE, SORT often is used with redirection and piping.

Issuing the SORT Filter

Use the following syntax for the SORT filter:

SORT /R /+n

/R reverses the sort order, and n is the offset column for the sorting process.

The SORT filter processes information that normally goes to your screen or to another output device. The text from the input is analyzed on a line-by-line basis and sorted according to the ASCII binary values of the characters. This order is alphabetical, but SORT doesn't discriminate between upper- and lowercase letters.

When you use SORT with redirection or piping, more sophisticated sorting occurs. The most common use of SORT is to sort a directory listing into a text file, which you then can print.

The offset—the /+n option—in the command shows the leftmost column to be sorted. With a directory listing, you can sort by date or file size rather than by root name. Table 13.5 lists the offset values for a directory listing.

Table 13.5. Offset Values for SORT

Offset Value Sorting By
1 Root name
10 File extension
14 File size
24 File date
34 File time

The sorted output appears onscreen; the original directory listing itself remains unchanged.

Note

This use of SORT is not as vital as it once was. Beginning with DOS 5.0, you can sort a directory listing by using the /O switch. To sort a directory by name, you can use the following command:

DIR  /ON

Similarly, you can use /OE to sort by extension, /OS to sort by size, /OD to sort by date and time combined, and /OC to sort by compression ratio (for DoubleSpace volumes). You still need to use SORT if you want to sort the directory by time alone.

Using SORT to Sort Subdirectory Listings

You can use redirection and piping, as well as the FIND and SORT filters, in many ways. In DOS 4.0, 4.01, or 5.0, for example, you can create a sorted list of the subdirectories in the root directory by using the process outlined in the next paragraphs.

To create a sorted list of subdirectories in the root directory, follow these steps:

  1. Type the following command:

    TREE C: /A | FIND "-" | SORT /+2 >TEMP.LST
    

    When issued with the /A switch, the TREE command produces a listing that uses the nongraphics character set. The FIND filter then removes all lines that are not subdirectory names. SORT sorts the output from FIND on column 2, and the output is redirected to a temporary file.

  2. Use the temporary file as the input to the FIND filter, which removes all directories that are not in the root, by typing the following command:

    FIND /V "|" <TEMP.LST
    

The result is an alphabetical list of all subdirectories in the root directory.

General Rules for Using SORT

The following are some helpful rules to know when using SORT:

  • If n is not specified, DOS assumes column 1.

  • Lines are sorted according to their ASCII binary values, with two exceptions. SORT is not case sensitive; for example, the command sorts A and a as they occur in the source file. Additionally, SORT sorts characters with values greater than 127 in the order determined by the current COUNTRY code setting. (See Chapter 16, “Understanding Batch Files,” for more information.)

  • The output filename must be different from the input filename when you use redirection.

  • The largest file the SORT program can handle is 64KB.

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

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