DOS

Computational Methods in

Environmental Engineering

Spring 1996


Table of Contents


DOS File Name

DOS stands for Disk Operating System. As implied by the name of the operating system, the central object here is a disk drive that holds files. A "physical drive" is a physically distinct device. A "logical drive" is a name assigned by the operating system to a physical device or several physical devices collectively. A logical disk drive does not necessarily correspond to a physical one. For example, drive C: and drive D: may both reside on the same physical drive. These two drives may occupy different physical locations on an actual drive (as in disk partition), or they may share the same physical locations (as commonly practiced in networking and as in the DOS command "subst"). On the other hand, two or more separate disk platters may be referred to with the same drive name, say C:.

Everything is stored on a disk as a file. I emphasize "everything" because the operating system (except for a brief bootstrap that resides on the 0th sector to start up the computer), all application programs, program data, and subdirectory information (such as file name, file location, file attributes, data/time of creation) are all stored as a file. The only exceptions are the file allocation table (FAT) and the main directory; these two items resides at the well-defined starting sectors on a disk.

A file is identified by its name, which we uniquely specify as:

     d:\path\filename.ext
where
"d:" is the logical disk drive,
"path" is the directory,
"filename" is the part of the name (up to 8 characters in DOS) preceeding the period, and
"ext" is the file extension (up to 3 characters in DOS).
Names for disk drive, subdirectory, and file (as well as commands) are all case insensitive in DOS. However, UNIX is case sensitive. Whereas UNIX separates subdirectory levels with a slash character "/"; DOS does it with a backslash character "\".

We cannot construct a file name with the following characters because of the special meaning associated with each of them in DOS. We may use all other characters, including @#$%&!_-(){}'`^~ and ASCII 128 through ASCII 255.

Invalid Characters in a DOS File Name:

   --------------------------------------------------
   Char  Description
   --------------------------------------------------
     ]
     [
     +   combine files
     /   qualifier
     *   wild card character (match any multiple characters)
     ?   wild card character (match any 1 character)
     <   direct screen input from a file
     >   direct screen output to a file
     ,   file separator
     .   file extension
     ;   parameter terminator
     :   disk drive
     "   literal quote
     =
     \   root directory, subdirectory separator
     |   pipe
   --------------------------------------------------
In addition, the following file names are pre-assigned to certain devices. (Colons are sometimes optional.) You can issue them in place of traditional file names whenever file names are expected.
CON:
Console (screen display for output and keyboard for input)
PRN:
Printer. This is usually LPT1.
LPT1:
The first parallel printer/port. The printer device may be used only as an output device.
LPT2:
The second parallel printer/port (for output only).
LPT3:
The third parallel printer/port (for output only).
COM1: or AUX:
The first asynchronous communications adapter port.
COM2
The second asynchronous communications adapter port.
NUL:
A nonexistent device to avoid the generation of output from programs.


Redirection

Usage:

     command >[d:][path]filename    ... redirect output
     command >>[d:][path]filename   ... redirect output (append)
     command <[d:][path]filename    ... redirect input
By default, display is the standard output device, and keyboard is the standard input device. In DOS, "con" serves as this standard input and output device. For example, when you issue the DOS command "dir", the computer displays the results on the screen because it is the standard output device. However, you may redirect the standard input and output devices to files or devices other than "con". If you append your DOS command line with a ">" sign followed by a file/device name, then the output from that program is redirected to the specified file/device. As an example, if you want to print the results from the DOS command "dir" or save it in a file named "c:\save.doc", you can do the following:
     dir > prn:
     dir > c:\save.doc
In the above example, the computer creates a file named "save.doc" under the main (\) directory on the c: drive and sends all output that are normally displayed on the screen to that file. If the file "save.doc" already exists, it is truncated to zero length without warning and then written over. (Translation: the original file is destroyed beyond recovery.) If you want to append to the end of an existing file instead, you add another ">" sign. With ">>", the computer opens an existing file and positions the write pointer at the end of the file so that all output from the program is appended to the file. The computer creates a new file only when the file does not already exist.
     dir >> c:\save.doc
If you want to suppress all output, you can accomplish this by redirecting the output to a special device named "nul".
     program >nul
Similarly, if you want all standard input to a program to come from a file instead of from the keyboard, you redirect the input. Redirecting the standard input is useful when a program requires a long list of input. You can save a lot of trouble and have a record of the input when you run the same program repeatedly, perhaps each time with only minor modifications in the input. All input normally expected from the keyboard must be contained in the file; otherwise, processing will stop and the computer may remain inactive/stuck when the end of file is reached. For example, the DOS "sort" program takes a series of lines you type in and sort them alphabetically. However, if you want the input to the "sort" program to come from a file named "input.lst" instead, you issue:
     sort < input.lst
An example of redirecting both the standard input and output.
     sort output.txt


Piping

Usage:

     command1|command2[|...]
Piping directs the standard output of the first program to the standard input of the second program, thus effectively chaining a series of programs together as a single command. It allows the screen output of one program to be channeled into the keyboard input of the second program. Any program that reads its input from the standard input device (i.e. keyboard) and writes its output to the standard output device (i.e. screen) can act as a filter and be piped. The names of the programs to be chained are separated by the vertical bar (|) character on the command line. The output from each program is stored by DOS in a temporary file in the root directory of the default disk; so, there must be sufficient space on the disk to store these files. The temporary files are deleted at the end. In essence, the above one line is equivalent to the following set of separate commands with redirection:
     command1 > temporary
     command2 < temporary
     del temporary
A simple example that sort the directory listing in alphabetical order:
     dir|sort
In the following example, the output from the DOS "dir" command is sent to the "find" command. Each line that contains the time stamp "2-12-96" is sent to the "sort" command, and the sorted file listing is sent to the printer. See above for information on redirection using ">".
     dir|find "2-12-96" |sort >prn
An another example, two variables separated by "|" are set in one DOS command line (no space between "abc" and "|").
     set var1=abc| var2=def


Return to Prof. Nam Sun Wang's Home Page
Return to Computational Methods in Environmental Engineering (ENPM808C)

Computational Methods in Environmental Engineering -- DOS
Forward comments to:
Nam Sun Wang
Department of Chemical Engineering
University of Maryland
College Park, MD 20742-2111
301-405-1910 (voice)
301-314-9126 (FAX)
e-mail: nsw@eng.umd.edu