The magazine of the Melbourne PC User Group

Beginners' Bytes: Part 9
Ron Wilby

This month, back to DOS for some more advanced topics. We will still be calling this series "Beginner's Bytes", although any reader who has followed all these pieces is now past the beginner status and can likely use some more advanced material. 

The DOS Redirection Operators 

Most DOS commands send their output to the "standard output device." Unless you've done something exciting to dear old DOS this destination is the screen. The DOS redirection operators are then used to redirect your Input or Output to places other than the default standard output (the screen) or default standard input (the keyboard). We use the "greater than" operator ">" to redirect the output of a program. For example, if you type

DIR > PRN

at the DOS prompt, the output of the DIR command will go directly to the printer PRN. If at the A:\> prompt we have

A:\>dir > DIRFILE

the output of the DIR command is sent directly to the file DIRFILE, overwriting anything already in that file.

We have also the "much greater than" operator ">>", which appends the redirected output to the file to which it is sent, instead of overwriting. If necessary, DOS will create the destination file.

The DOS Filters, MORE, FIND and SORT

Part of DOS's duties is the channelling of information between devices. DOS filters modify that information while moving it. Note that these filters work only on ASCII text files (files created by DOS), not on files produced by wordprocessors or other programs. The filters are often used together with the redirection symbols, so we can have input from various sources and send the output to devices other than the screen.

The MORE Filter 

The command MORE "buffers" information. To buffer means to store the information in a temporary file, releasing it in blocks as required. With the MORE command, each block is one screen at a time. Thus, if you have a large directory so that DIR A: causes the list of files to "scroll" off the screen, you could use the command

MORE < DIR A:

This produces a display of one screenful of information, then pauses with

- - More - -

at the bottom of the screen. You then "press any key" to get another screenful of information. (Of course, you can also do this with DIR/P, but MORE has other uses).

One way in which MORE is extremely useful is with these wretched "README" files that come on various floppies. When you try to read them, your command "TYPE README" results in the text scrolling rapidly oft' screen, so that all you get is the last page.

So you use your wordprocessor? MORE may be quicker. The commands are:

TYPE README | MORE

or better

MORE < README

What's this | character, you are saying? Hang on, I'll get there soon.

MORE collects the information from README, storing it in a temporary disk file. When MORE has one screen of information, it sends it to the screen all at once. Then you get the
- - More - - prompt which, when you "press any key," displays the next screen and so on till the end of the file. The MORE program erases the temporary file after use.

My personal preference is to have the shareware program LIST available at all times. I then type LIST README to view the file with ease. As Doug Brooke says, "I couldn't live without LIST."

A Useful Tip

It often happens (to me) that the display I want has two pages with - -More - - in the middle somewhere. Inevitably the data I want has scrolled off the screen or has not come up yet. I need to see both pages at once. A good example of this occurs with DOS MEM/C command. It comes in two separate pages and you are always looking at the wrong one. And, of course, you can't scroll backwards. So here's my tip: Use your word processor in ASCII mode or the DOS Editor to create a one-line file that reads

MODE CON LINES=50

Call this file 50.BAT. Create another file that reads

MODE CON LINES=25

Call this file 25.BAT. Put these two files in your root directory or anywhere in your path. Before using MEM/C or whatever, simply type 50 and press Enter. This changes your display to 50 horizontal lines and you will have two pages displayed at once. You have to "press any key" when - - More - comes up, but the first page does not disappear, MORE simply adds the second page on screen under the first page. To return to your normal 25-line display, type 25 and press Enter.

The FIND Filter

The FIND Filter can find strings of ASCII text in files. The command is FIND, but there are several switches you can use. Consult your DOS manual, as these vary with DOS versions. FIND can find all files on a disk that have a particular extension, for example, or you can use FIND to locate occurrences of a particular word. Your word processor may be able to do this better than FIND.

The SORT Filter

Lines are sorted by various characteristics depending on the switch in use. SORT/n sorts from the column number n in the line. Thus if your command is SORT/1o, SORT will look at the tenth column and sort on that. If it is a DIR listing, the 10th column will contain the first letter of the file extension. The default value for SORT is n=1, which sorts on the file name alphabetically. Utilities such as Norton and PC Tools and particular Applications may do this better than DOS.

The DOS Pipe

The pipe, that I character you were waiting for me to tell you all about, is another redirection operator. It redirects the output of one program to become the input of another program, as in

A:\> DIR | MORE

where the output of the DIR command, on drive A:, instead of going to the screen, becomes the input to the MORE command. Some more examples of what you can do (the A:\> is the DOS prompt for the A: drive - you don't type this).

A:\> DIR | SORT > SORT.DIR

Here the output of the DIR command is piped to the SORT command. The output of SORT is then redirected to the file SORT.DIR. Thus we write a sorted directory to the file SORT.DIR, on drive A: unless we specify otherwise.

A:\> TYPE MAIL.LST | SORT | MORE

Here the MAIL.LST file is piped to SORT and the sorted output is the input to the MORE program, which displays it one screen at a time.

Printer Drivers

What is a printer driver (sometimes called Printer Description File and similar names)? It's a file needed so that your program can work with your printer. The wrong printer driver will result in your printer's output being very different from what you expect. Application programs come with printer drivers included. My now superseded version of WordStar, for example, comes with seven 360 kB floppies labelled "Printer Data" and containing drivers. I quote from WordStar's manual. "Every time you install a printer, WordStar creates a Printer Description File (PDF), a small file that includes the information needed to make WordStar work with that printer." You then have a default printer and its PDF, and you specify these when installing the WordStar program (or WordPerfect or whatever you use). That default printer and its PDF are assigned to every file created.

Recently some people have come to me with printer driver problems. Let me reassure them-everyone has these problems sooner or later. They can only be avoided by having your system properly set up so that your computer can work with your printer, and then on no account must you change anything. For example, don't buy a new printer. If you do, try to ensure that your application program supports your new printer. However, if it doesn't, the major software houses are very helpful in supplying printer drivers for unusual cases.

Where problems do occur is because people "print to disk," for transfer to another person's system. This is not the way to do it! To send a file elsewhere, simply copy the file to a floppy and post it off. When printing to disk, you may get a file that "looks like" the actual printout, with headers, footers, margins and other formatting. This will definitely not print out correctly on another computer with a different printer.

Printer Drivers and Your New Program

So you have just arrived home with your newly acquired latest version of your favourite word processor. You can't wait to get on with the installation of your program. Don't forget to make backup copies of the floppy disks you just paid good money for, and scan them for viruses. Then, in the installation routine, you get an enormous list of "supported" printers from which you are required to select one. This is how you tell your new program the name of your default printer and which printer driver it needs. Now you find that Murphy has been here and that the printer you actually have is never, never one of the supported ones.

So, go to your printer manual to discover which listed printer your machine "emulates," and use this name during installation. Of course, often there is no emulation mentioned in the manual. Murphy again. What to do? Try the local distributor for your program. They may be able to supply a driver for your printer. If not, you may have to experiment. For example, try telling your application program that your printer is one of the supported ones, then do some printing to see what you get. If this is not too successful, try again and again, telling your application that you have a different supported printer, until you find the best compromise solution. A print test file is very useful here and some applications include a suitable file, which checks things such as whether you can print unusual characters, subscript, superscript, underline, or boldface.

More About Device Drivers

The printer drivers discussed above are only one variety of device driver. Device drivers are specialised program modules that DOS uses for control and communication. There are several device drivers that come with DOS. Additionally, since DOS is not designed to understand every possible piece of equipment you may include in your system, extra device drivers are used. These are separate program modules that can be installed on your computer so that DOS can talk to the various components of your system.

The device drivers that come with DOS are divided into two classes, "resident" and "installable." The resident drivers are in the "hidden" system file IO.SYS (IBMBIO.COM in IBM's PC-DOS) and they can vary with different brands of computer. They will also vary with different versions of DOS. Some examples of resident drivers are:

CLOCKS: The system clock device driver.
CON: The keyboard as input and the s creen as output driver.
AUX or COM1 The first serial port, which is the gateway through which data may be received or transmitted to other computers.
LPTI or PRN: The first parallel port, normally used to send data to the printer.

The installable device drivers can modify or enhance the performance of the resident drivers. Actual installation occurs via the "Startup" file, CONFIG.SYS, discussed in Part 7 of this series. Examples are:

EMM386.EXE:  EMM386.EXE: A memory management program.
HIMEM.SYS: HIMEM.SYS: Manages extended memory.
RAMDRIVE.SYS:  RAMDRIVE.SYS: Enables the use of memory to simulate a disk.
ANSI.SYS Gives DOS more elaborate control over the display. This device driver may justify a page of PC Update all to itself, but for now we have run out of space.

That's all for this month. Till next time . . . 

Reprinted from the June 1994 issue of PC Update, the magazine of Melbourne PC User Group, Australia

[About Melbourne PC User Group]