First steps towards system programming under MS-DOS 7/The command line

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Chapter 2 Command line

Command line in MS-DOS begins with a machine-generated prompt and then is implied to be filled with symbols and words which altogether must be suitable for machine interpretation according to certain syntax conventions. The final ENTER keystroke initializes interpretation of command line by a resident program — the command interpreter. Implementation of syntax conventions by different interpreters is not just the same.

MS-DOS 7 provides 3 interpreters: IO.SYS, COMMAND.COM, and DEBUG.EXE. Each interpreter accepts its own set of commands, described in chapter 4 for IO.SYS, in chapter 3 for COMMAND.COM and in part 6.05 for DEBUG.EXE. Since the loader IO.SYS deals with command lines in configuration files only, the user first encounters command line, presented by COMMAND.COM. The latter is often called resident interpreter, because it is permanently loaded into computer's memory and therefore is always ready to perform commands entered from keyboard.

By means of input redirection (see 2.04-02 for details) one can force the interpreter to accept commands not from keyboard, but from command files. Each line in command files is in fact a separate command line. Sending command files via input redirection is the only way to automate execution of command sequences by the DEBUG.EXE interpreter (examples in 9.02).

The COMMAND.COM interpreter too can accept commands via input redirection, but it is not the best way to execute command sequences for COMMAND.COM, because it is able to handle a special sort of command files — batch files — without redirection. From batch files the COMMAND.COM interpreter accepts a number of supplementary commands which cannot be executed from the command line or from ordinary command files. These supplementary commands include substitution of dummy parameters and names of variables with their values (2.03-03), search for labels and some other commands (3.02, 3.14, 3.21, 3.27). Here and forth in this book the term "batch files" is applied only to this special sort of command files. Examples of batch files are shown in part 9.03. Configuration file AUTOEXEC.BAT (9.01-02, 9.04-02, 9.09-02) also represents an example of a typical batch file.

This chapter describes the most essential conventions which define command line composition both in separate command lines and in command files. These conventions are common to some extent for all the three interpreters in MS-DOS 7. Endemic features of interpreters are presented too. If not specified otherwise, interpretation of commands by the main interpreter — COMMAND.COM — is implied.

2.01 Named objects and their names[edit | edit source]

Each command line addresses one or more objects. An object may be, for example, a separate utility which is to perform the desired action, or an internal command of command interpreter. The data in command line must be ample enough to identify exactly the addressed object(s). For this purpose inside any common directory identical names of objects are not allowed: all files and subdirectories must be given different names. In order to identify any object outside any particular directory the path to this object is taken into account. The path may be specified explicitly or set by default.

The main object’s name together with its optional path should be the first specified in command line and may be followed by other items, including name(s) of other object(s), parameter(s), reference(s), syntax mark(s), etc. Each line of the command files presented in section 9.03 can be taken as example of command line.

There are objects, however — internal commands, ports and some others — which cannot be defined by path specification. The names of such objects must be unique, reserved words which shouldn't be assigned to any other object. Therefore the first theme to consider is which names may be assigned to objects by the user, and which can't.

2.01-01 Reserved words[edit | edit source]

Reserved words represent names of internal commands, specific for each interpreter, and names of devices, claimed as existing in a particular computer. Names of these objects can't be altered or assigned to other objects. Nevertheless the reserved words should be known in order to prevent attempts to assign such names to other objects which can be named by the user.

Internal commands are those performed by a particular interpreter itself. All those names of internal commands, described in chapter 3, are regarded as reserved words as long as command line is interpreted by COMMAND.COM. For example, you can't assign the name PROMPT to a file, since COMMAND.COM, having encountered this name in command line, "understands" it as its own internal command and has to do nothing but perform this command. Other command interpreters similarly don't allow to assign names of their internal commands to other objects.

Reserved names of devices in a PC define sources for obtaining data or targets for sending data. Most known device names are:

AUX – first serial port
COM1 – first serial port (equivalent to reserved name AUX)
COM2 – second serial port
CON – console, i.e. keyboard for input and display for output
LPT1 – first parallel port
NUL – virtual "nowhere" output port
PRN – first parallel port (equivalent to reserved name LPT1)

Besides these some other device names are regarded as reserved : CLOCK$, COM3, COM4, CONFIG$, LPT2, LPT3. These words are reserved by device drivers integrated into DOS's core, always present even if corresponding device is not physically present. The entire list of devices that are claimed present in your PC can be displayed by the MEM.EXE utility (6.17), if it is launched with /D parameter. This utility displays a table, and all registered names are shown in its 4th column. Reserved words are shown shifted by 3 spaces to the right against other names.

Several installable software drivers also can be identified by name and reserve words for this purpose. For example, SETVER.EXE driver (5.01-02) reserves word SETVERXX, HIMEM.SYS driver (5.04-01) reserves word XMSXXXX0, EMM386.EXE driver (5.04-02) reserves word EMMXXXX0. Moreover, when you specify an arbitrary identifier for a CD-ROM drive, for example, MSCD001 (see 5.09-01, 5.09-02, 5.09-03), this name becomes registered by DOS as a reserved word. If later you'll try to assign this name to a file, DOS will reject your attempt.

2.01-02 Names and suffixes[edit | edit source]

Naming and renaming operations most often are applied to directories (3.19, 6.20) and to files (3.24, 3.25), both ordinary and executable ones. Names in DOS consist of no more than 8 characters and may be appended with an extension (suffix) of no more than 3 characters long. Suffix is separated from the name with a dot. When suffix is assigned, but is not required for a particular operation and is omitted, then the dot separator must be omitted too.

Both names and suffixes may be composed of letters, digits and several signs which have no dedicated functional mission in parsing of command lines: number sign ( # ), dollar sign ( $ ), ampersand ( & ), minus (– ), exclamation mark ( ! ), underscore ( _ ) and a few others (2.04-06). Upper case and lower case letters are regarded equivalent in almost all operations, except letters in strings to be compared with commands IF (3.15-02), SEARCH (6.05-16) and FIND (6.14).

Since dot ( . ) is used to separate a name from suffix, it is not allowed to be employed as an ordinary character. Other prohibited signs are comma ( , ), colon ( : ), semicolon ( ; ), equality sign ( = ), question mark ( ? ), plus ( + ), left arrow ( < ), right arrow ( > ), asterisk ( * ), pipe ( | ), slash ( / ), backslash ( \ ), and double quotes ( " ). National language symbols also can't be employed, unless restrictions on their usage are taken off by the COUNTRY command (4.05, 5.02-01, A.02-5).

Directory names usually have no suffix. Suffixes in names of files are used to indicate file's type or origin. Three suffixes : BAT, COM and EXE, have special status, since they are recognized by the COMMAND.COM interpreter as belonging to executable files. When a filename with either of these suffixes is specified the first in command line, COMMAND.COM automatically tries to execute the file's code. If there is something else than valid executable code, the computer most probably would "hang". These suffixes shouldn't be assigned to files which are not definitely executable and valid.

Assignment of other suffixes is not so critical, but nevertheless should be submitted to common restrictions. File managers are able to link files with certain extensions to devoted applications, for example, files with suffix BAS may be automatically sent for execution to BASIC language interpreter. It is convenient to have every file automatically directed to the appropriate program (examples in 6.25-03, 6.25-04). Suffixes also may be helpful for visual recognition of essential file's classes. The list below shows some suffix associations, commonly used in DOS environment.

BAK – archive or old version of a file
BAT – batch file, interpretable by COMMAND.COM
BIN – executable file which requires fixed placement
BMP – raster image file (Bit-Map-Picture)
CAB – compressed file for software distribution
COM – executable file without a header
CPI – library file with font data for DOS
DAT – files with non-textual data of various kind
DOC – textual file, produced by the WORD editor
DLL – Dynamically Linked Library of executable codes
EXE – executable file with control data in header
EXT – specifications of functional extensions
GIF – Graphic Image File
HTM – file written in HyperText Markup language
INI – file with initialization data
JPG – image file, compressed according to JPEG specification
RAR – compressed archive file, packed by RAR.EXE
RTF – textual file of Rich Text Format
SCR – file with command lines, interpretable by DEBUG.EXE
SYS – system file, either textual or installable
TMP – temporary file
TXT – non-formatted textual file
ZIP – compressed archive file, packed by PKZIP.EXE

Associations for a lot of other suffixes can be found in internet site .

2.01-03 Filemasks and wildcards[edit | edit source]

Question mark ( ? ) and asterisk ( * ) are known as substitution symbols (or wildcards) which cannot be employed in names and extensions, but can be used to replace characters in specifications of names and suffixes in command line(s). Name specification with wildcard(s) is a filemask — a means to address several files at once.

While parsing a command line with a filemask, COMMAND.COM may invoke wildcard expanding function that searches for filenames, satisfying to the encountered filemask. If such file is found, its name is substituted for the filemask, and then command line with this name is executed. If more than one such file is found, similar procedures are performed sequentially with each of the found filenames.

Whether words with wildcards will be interpreted — it depends on the command to be executed: some commands invoke a call for the mentioned wildcard expanding function, some commands don't. Generally wildcards are not ignored, but there are some exceptions :

  • wildcards are not expanded by internal commands ECHO, SET, TYPE and IF with equality comparison function (see chapter 3).
  • wildcards in parameters of a batch file are not expanded (it doesn't matter whether the CALL command is used or not);
  • input redirection notation (2.04-02) doesn't expand wildcards;
  • the FOR command (3.13) expands wildcards inside brackets only, but outside brackets wildcards are transferred "as they are" to the command to be executed inside the FOR cycle, and further fate of wildcards depends on that command.

Wildcard (?) means a symbol which induces comparison procedure(s) to give positive response for any single letter or digit. When the (?) wildcard in a filename or in a suffix is not followed by any explicitly specified letter or digit, comparison procedures also give positive response to absence of any symbol in that place. For example, in a command

DEL readme.??

the object will match all files in the current directory having name "readme" and not more than two-character suffix :, readme.en, readme.f, and so on. Hence the DEL command (3.09) will delete all such files from the current directory.

Asterisk ( * ) means a symbol which induces comparison procedure(s) to give positive response for any number of any following letters or digits up to the end of the word, which may be marked with either a dot or a space. For example, asterisks in command DEL C:\TEMP\*.* match any filename with any suffix, so this DEL command will be applied to all the files inside the specified directory.

Numerous examples of wildcard usage are shown in 2.02-03, 9.09-02 and in several other batch files in chapter 9.

  1. Whether the attributes will be taken into consideration during a search for files, satisfying to a filemask, — it depends on the command to be executed. For example, wildcard expansion by the ATTRIB command (6.01) includes all files without exceptions.
  2. Interpreters IO.SYS and DEBUG.EXE don't accept wildcards. While CONFIG.SYS file is interpreted by IO.SYS, the question mark is treated not as a wildcard, but as a prompt (see 4.06, 4.07, 4.15, 4.16, 4.25).

2.02 Paths[edit | edit source]

Exact placement of each file on a disk is specified in a certain directory. Numerous directories are usually arranged in a hierarchical structure: each directory of higher rank may contain data not only about files, but also about placement of several lower rank directories (subdirectories). In order to access any file you have to point out the disk and the path — that is a directory and the whole chain of subdirectories, leading to the one, which contains exact placement data for this particular file.

DOS gives you an opportunity (2.04-01, 3.03) to specify any one particular path as the default path. This path will be stored in internal DOS's data table (A.03-3). Each time you enter a command line without path specification, DOS takes into account the stored default path. The disk and the final directory (subdirectory), specified in the default path, are known as the current disk and the current directory. DOS's prompt (3.22) is usually adjusted to show the current path.

2.02-01 Typical path structure[edit | edit source]

By default the command interpreter searches for the addressed object in the current directory. If the object must be found in any other directory, object's name should be preceded by a path, for example


where : – is the addressed executable file ;
C:\DOS\MS7\ – is an example of a path to this file.

The shown path specification directs the search process: first it should be switched to the root of disk C:, there the DOS directory should be entered, then – its MS7 subdirectory, and at last in the latter directory the specified executable file should be searched for. If you happen to have other directory structure, you'll have to specify other names, but the principle remains the same: first the disk’s letter-name, followed by a colon, then a chain of directory names, separated with backslashes, and finally a name of the addressed object.

Specifications terminated with a backslash are considered in MS-DOS as having no target object and hence not complete. Such paths are either ignored (see 2.04-01) or regarded as not valid, except one special case — the path, reduced to a single backslash. Single backslash after a disk's letter-name means a path to the root directory of the specified disk. For example, A:\ means a path to the root directory of disk A.

Paths without disk’s letter-name (for example: \DOS\MS7\ are reckoned from the root directory of the current disk, whichever disk is current at the moment. This is important for writing media-independent batch files (9.01-01, 9.04-01, 9.09-01). Single backslash is interpreted as a path to the unnamed root directory of the current disk. Command to change the current directory (3.02) with the following backslash CD \ performs a jump to the root directory of the current disk, whichever it is.

When there is no both disk and root specification at the beginning of the path, it is reckoned taking the current directory as the start point. For example, the path DOS\VC4\ implies that the first subdirectory DOS exists inside the current directory, otherwise an error message will be displayed.

2.02-02 The PATH variable[edit | edit source]

In order to make command line usage easier DOS provides one more mechanism of path specification — via the PATH environmental variable. This mechanism comes into action when 4 conditions are met :

  • command is addressed to the COMMAND.COM interpreter;
  • PATH variable is present yet in the environment;
  • path is not specified in command line;
  • the first addressed object isn't found in the current directory.

If all these conditions are met, then DOS will search for the first addressed object along all the paths which are implied to constitute the value of the PATH variable. The PATH variable should be set beforehand with internal PATH command (3.20). Examples of paths specification with PATH command are shown in 9.01-02, 9.04-02, 9.09-02.

Owing to the PATH variable you can call utilities for execution as easily as though these were always present in any directory you may choose. This is convenient, but only until it happens to encounter in the current directory a synonymous version-specific utility, belonging to other version of DOS. Then the latter utility will be found first and will fail, leaving an error message. Different approaches to the problem of avoiding such conflicts are discussed in article 5.01-02 and in introduction article to chapter 6. This problem also may be solved by specifying full paths in command files or in configuration files. Examples of such solutions are given in part 9.03.

2.02-03 Dot(s) in path specifications[edit | edit source]

A dot ( . ) in path specifications is interpreted as an alias for the current directory. Note, for example, the trailing dot which replaces the target path in the following copy command :

Copy /B A:\MyDir\*.* .

Sometimes batch files must be written so as to do their job in any current directory (which may be not known beforehand), and then the dot alias is the only allowable replacement for required specification of target path to the current directory. Addressing to the current directory with a dot is also needed when any other (not current) directory will be implied otherwise.

Dot as the first symbol of a path statement means that the path should be reckoned taking the current directory as the start point :


Such path is equivalent to the one without preceding backslash (2.02-01), but nevertheless this form of path may be practical in batch files, because MS-DOS provides no other means to get rid of preceding backslash. One more reason to use commands with preceding dot alias and a backslash is to prevent search for synonymous utilities throughout all the paths, enlisted in the PATH environmental variable, when execution of a synonymous utility may inflict unwanted consequences.

Some utilities return directory specifications with final backslash, for example :


Such paths are regarded by MS-DOS as invalid, and MS-DOS doesn't provide means to get rid of the final backslash. Appending a dot to such path solves the problem :


- this directory specification is regarded valid.

Double dot, or dot-dot (..) may be used in any place within path statements just like the single dot, but dot-dot is an alias for the parent directory. If, for example, you are given specification C:\DOS\MS7\ and want to address its parent directory, then the C:\DOS\MS7\.. specification is exactly equivalent to C:\DOS.

While parsing a path, containing a double dot alias, DOS simply throws out the preceding element of path's chain (the \MS7\ in the last example). DOS doesn't check whether the thrown element exists, whether it represents a file or a directory. This gives an opportunity to address a new file in a directory, unknown beforehand, on a basis of a path to another file, obtained during execution. Examples of such addressing are shown in article 6.25-03.

Double dot without any preceding path is interpreted as an alias to the parent directory with respect to the current one, for example, in a command to change current directory (3.03) :

Cd ..

In order to climb two levels up the tree of directories structure, you have to combine double dot twice:

Cd ..\..

Some even more complex double dot combinations may be used to navigate and to explore directory trees.

2.03 Tips on command line parsing syntax[edit | edit source]

2.03-01 Separation symbols[edit | edit source]

Words in command line are separated with separation symbols: space ( ), comma ( , ), equality sign ( = ) and semicolon ( ; ). Though space is the one most universally used, either of these is ignored at the beginning of command line and will act as separation symbol in parsing operations, including parsing of an object list within the FOR command (3.13). Because of the same reason separation symbols can't be transferred from parameters of command line into internal dummy parameters of a batch file (2.03-03).

There are some exceptions, though. Commands SET and IF use equality sign ( = ) in a special way and don't allow to use it for separation. When symbols comma, semicolon or equality sign precede to ECHO command, then displayed part the line will begin just after the separation symbol, including possible preceding spaces and the word ECHO itself. Semicolon ( ; ) is used as special separator in PATH command (see 3.20).

The IO.SYS interpreter deals with semicolon otherwise. Being placed first in a line within Config.sys or Msdos.sys file (5.01-01), semicolon is interpreted as a command to jump to the next line, ignoring the rest part of current line (usually containing commentaries). The DEBUG.EXE interpreter in assembler mode deals with semicolon in a similar way: it ignores the rest part of a line after semicolon and thus enables to supplement DEBUG's command files with remarks (7.01-05).

2.03-02 A slash[edit | edit source]

A slash ( / ) in MS-DOS command line specifications is a sign to interpret the following letter (or word) as a parameter. For example, in the command DEL C:\TEMP\*.* /P (see 3.07), slash ( / ) forces to interpret the letter P as parameter, inducing a prompt on whether each file in the specified directory should be deleted. Exact place and form of the parameter(s) are specific and must conform to particular command's specifications. Sometimes a slash ( / ) is used within the FOR command as a functional separator, causing conversion of letters in the following word to the upper case (see 3.13 for details).

2.03-03 Percent sign[edit | edit source]

Percent sign ( % ) in batch files means substitution of the name of a dummy parameter or of a variable with the value of the same parameter or variable. These substitutions are performed before execution of the specified command(s) and redirection(s).

Dummy parameters are named with digits from 0 to 9. Value of the 0th dummy parameter is always the name of the batch file itself; other dummy parameters take their values from the items, specified after the name of batch file in the command line, from which the batch has been started. So %3 ,for example, will be replaced with the third item, following the name of batch file in command line. If several dummy parameters are specified without a space in between, then after substitution their values will be concatenated. Examples of assigning values to dummy parameters are shown in 2.03-04 and in 9.03-01.

If total number of words, following the name of a batch file in command line, is less than 3, then the designation %3 of a dummy parameter will be replaced with nothing and disappears without any error message. If total number of words, following the name of a batch file, is greater than 9, then the values of the rest can be accessed after applying a shift to dummy parameter numeration (3.27). There is one exception, though : the Autoexec.bat file (for example, 9.01-02), automatically executed during DOS loading procedure, has no dummy parameters at all, so the CALL %0 command (3.02) doesn't induce its recursive execution.

Names of variables must be a single word with a letter (not a digit !) as their first character. Values of variables either are assigned by special command SET (3.23) or are inherited from parent environment, belonging to the program which has launched execution of the current program (see 6.04). For performing substitution the name of the variable in command line must be surrounded with percent signs on both sides (%VAR%, for example). Numerous other examples of command lines with environmental variables are shown part in 9.03.

  1. If percent sign is to be transferred without substitution, you have to specify it twice (%%). During interpretation of command line the doubled percent sign doesn't induce replacement, it is simply transformed into a single percent sign.
  2. The FOR command (3.13) employs its own local variable; its name outside batch files must be specified with only one (preceding) percent sign. Being used within a batch file, name of that variable needs two preceding percent signs, for example, %%A, because substitution shouldn't be performed in advance to the FOR command (see 3.13 for details).
  3. Other interpreters (IO.SYS and DEBUG.EXE) ignore percent sign and do not replace variables and dummy parameters with their values.

2.03-04 Double quote sign ( " )[edit | edit source]

Double quote ( " ) disables interpreter's function of parsing the command line until the next double quote is met in the same line. Thus any group of words between opening and closing double quotes (possibly including separation symbols, redirections, etc) will be interpreted as one item. Enclosing double quotes themselves are considered belonging to the enclosed item. For example, execution of a line

C:\>Batch.bat 1 " 2 3 " 4 ""

creates a new set of dummy parameters, in which the value of the first parameter is single digit 1, the value of the second is a string " 2 3 ", the value of the third parameter is digit 4, and the value of the last fourth parameter is an empty pair of double quotes. This set of dummy parameters will exist until execution of Batch.bat terminates. Enclosing a group of words in double quotes is a way to include this group of words as a whole (together with any symbols inside) in a value of one dummy parameter. This trick is used, in particular, to preserve integrity of long names in DOS.

An empty pair of double quotes ( "" ) is regarded as a special void symbol, enabling to preserve parsing sequence unchanged. Most internal commands in MS-DOS 7 (except ECHO, IF and SET) ignore empty pair of double quotes as a separate symbol, but accept the results of parsing affected by double quotes. For example, command

C:\>cd ""

is executed just as though there were no following symbols at all. When a parameter is enclosed in double quotes, command is executed as though there were no double quotes :

C:\>cd "C:\dos"

Existence of the closing double quote is not checked during parsing of command line, except parsing parameters for FIND (6.14) and FOR (3.13) commands. Both FIND and FOR commands perform parsing in a slightly different way: any group of words enclosed in double quotes is still regarded as one item, but double quotes are not considered belonging to this item. Therefore empty paired double quotes ( "" ) may be used in FIND command for counting total number of lines in textual files. For the same reason the FOR command enables to get rid of enclosing double quotes, when these are no more needed.

2.03-05 Square brackets[edit | edit source]

Square brackets [ ] are used as a special sign in files which are to be executed by DEBUG.EXE and by IO.SYS. Data in square brackets are interpreted by DEBUG.EXE as references to operands (see introduction article to chapter 7 for details).

In configuration scripts MSDOS.SYS and CONFIG.SYS, which are to be executed by the IO.SYS loader, the words enclosed in square brackets are interpreted otherwise: as headers, marking beginning of a separate configuration block and at the same time as signs, enclosing name of this configuration block. There are two reserved words that denote special configuration blocks in CONFIG.SYS file: [menu] and [common]. The [menu] block represents multiconfiguration menu; if it exists, it must be placed the first in CONFIG.SYS file. The menu block is eminent because of a special subset of allowed commands: the MENUCOLOR (4.19), MENUDEFAULT (4.20), MENUITEM (4.21) and SUBMENU (4.29) commands may be used only in blocks, announced as menu or submenu. All other configuration commands, described in chapter 4, except the NUMLOCK command (4.23), can't be used in menu and in submenu blocks.

Commands to be executed in all configurations are grouped in one or more blocks with the same name [common]. Outside block headers the names of configuration blocks are referenced without square brackets (4.14). Examples of configuration file CONFIG.SYS with blocks [menu], [common] and some others are shown in 9.04-01 and in 9.09-01.

2.04 Syntactic marks with command mission[edit | edit source]

2.04-01 Colon[edit | edit source]

Interpretation of a colon ( : ) depends on its place in command line. Being used as the first character in a line (in batch files only), colon ( : ) forces to interpret the nearest following word as a label, marking a target address point for a jump. There may be more than one word in this line, but all the rest words and symbols will be ignored. Double colon ( :: ) at the beginning of a line in a batch file is sometimes used in order to disable all operations, specified in this line, including redirection operations (2.04-02 – 2.04-05). A colon ( : ) in the second place in command line forces to interpret the preceding letter as a letter-name of a disk. If the following part of command line is empty, or is reduced to a single backslash, or is enclosed in backslashes, then the whole line is interpreted not as a path, but as a command to change current disk (make specified disk the default one). For example, in order to make disk A: the current default disk you may type either






and then press the ENTER key. A change of the current disk doesn't alter the default directory on this disk. If the current directory on the target disk is, for example, A:\DOS, it will preserve its status after default disk change in each of the examples above. In such commands any path, enclosed in backslashes, is not checked and even may not exist. In fact any full address, appended with a backslash, will fit as current disk change command.

2.04-02 Left Arrow[edit | edit source]

Left Arrow ( < ) denotes an operation of input redirection, prepared by COMMAND.COM interpreter for execution of the program, specified in command line to the left of Left Arrow sign. By default the standard input channel (STDIN) is linked with console (CON) and accepts input from keyboard. In fact Left Arrow is a command to link STDIN (handle 0000h) with the data source, specified to the right of input redirection sign. When the utility specified to the left of input redirection sign will ask DOS for data input via the STDIN channel, it will get data from this source. Of course, this works only if the utility asks for input via the STDIN channel. For example, command

MORE < C:\DOS\Filename.txt

supplies the filter utility MORE.COM (6.19) with data read from specified text file in C:\DOS directory. If directory specification is omitted, then current directory is implied. In any case the file to be read will not be searched for along the paths, enlisted in the PATH variable. Filemasks instead of the source filename are not allowed, wildcards (2.01-03) are not expanded.

Besides files, ports (LPT1, LPT2, COM1, COM2, COM3, COM4) may be used as sources of input data. If default links are disrupted by the CTTY NUL command (3.07), then for performing input from keyboard you have to use input redirection with explicit specification of the console (CON) as the data source (example in 3.07).

In any case of input redirection you must be sure that the specified source will be ready to provide the required data. Waiting for data input from an empty, idle or defective source most probably will cause hanging.

  1. Redirections are arranged by data substitution in JFT table (note 3 to A.07-1). Redirections, prepared by COMMAND.COM for execution of a program, may be cancelled by the program itself (example in 9.07-02).
  2. Other command interpreters (DEBUG.EXE and IO.SYS) ignore left arrow sign as well as other redirection signs (2.04-02 – 2.04-05). However, the redirections, prepared by COMMAND.COM, are accepted by DEBUG.EXE (examples in 9.02).

2.04-03 Right Arrow[edit | edit source]

Right Arrow ( > ) denotes an operation of output redirection, prepared by COMMAND.COM interpreter for execution of the program, specified in command line to the left of the Right Arrow sign. By default the standard output channel (STDOUT, handle 0001h) is directed to the console device (CON) - that is to the display's screen. Output redirection forces to direct STDOUT to another target - the one specified to the right of Right Arrow sign. For example, the DEL /? command (3.09) normally presents on-line help to display, but when it is followed by output redirection sign

DEL /? > Filename.txt

Its output wouldn't reach the screen, it will be written into the specified file. A new file with the specified name (Filename.txt) will be created automatically in order to write there the redirected output. If a synonymous file exists yet, it will be overwritten without prompt, and its former contents will be lost.

Besides files, allowable targets for redirection may be ports (LPT1, LPT2, COM1, COM2, COM3, COM4), printer PRN (which is usually equivalent to LPT1), display ( CON ) and special quasi-device NUL which acts just as a "black hole": any output becomes lost there for ever (example in 3.21). This is often used in order to get rid of unwanted messages.

If the default link between the STDOUT channel and the display device is disrupted by the CTTY NUL command (3.07), then sending output to display is still possible, but it needs explicit output redirection to CON device (examples in 9.03-02).

Output redirection can intercept only the data sent via DOS's normal STDOUT channel. Data sent via BIOS' interrupts (8.01-17, 8.01-21, 8.01-33), via DOS' INT 29 (8.02-88) and via STDERR channel for error messages (handle 0002h) can't be affected by STDOUT redirection.

If you combine input and output redirections in one line, then the main executable command must be first followed by input redirection with full source specification. Output redirection should be specified afterwards. Examples of combined redirections are shown in 6.14, 6.25-03 and 9.03-02.

All symbols of redirection (2.04-02 - 2.04-05) are assigned higher priority, than common operations, except labels (2.04-01) and double quotes (2.03-04). For example, after string input commands (ECHO, SET) all redirection symbols will not be processed as a member of the string, but rather will cause redirection. Because of the same reason redirection ignores conditions, set by IF command, and the only way to execute redirection conditionally is to bypass its line with conditional "IF ... GOTO" jump (3.15, 3.14).

Redirection will be executed even if the main operation in the same line is invalid, disabled or provides no output at all. Empty output redirection after the REM command (3.24) is often used to create a file of zero length.

Output of a batch file as a whole may be redirected only via loading a separate module of command interpreter COMMAND.COM with /C parameter (6.04) in order to execute this batch file (examples - in 3.22, 9.01-03). Without launching a new interpreter's module the output of a batch file may be redirected in a line-by-line manner from inside of this batch file, but not as a whole.

Output redirection should be used with caution, because together with anticipated output it may affect some warnings or invitations for certain action(s) sent to the user. For example, the DIR /P command stops its output after each screenful and sends a message via STDOUT, reminding that output will be resumed after any keystroke. When such messages and warnings are redirected, the screen remains empty, and PC seems having got hanged.

2.04-04 Double Right Arrow[edit | edit source]

Double Right Arrow ( >> ), just as single Right Arrow (2.04-03), is also a sign of output redirection, but its action is different, when target file for redirection exists yet. Rather than overwrite the target file anew, redirection with Double Right Arrow appends new data to former contents of the existing target file. All other peculiarities of output redirection with the Right Arrow (2.04-03) are applicable to Double Right Arrow as well.

2.04-05 Vertical bar (or "pipe")[edit | edit source]

Vertical bar or "pipe" separator ( | ) is a sign of intermediate redirection, i.e. data transfer from one utility (or command) to another. Especially for this purpose COMMAND.COM interpreter creates a temporary file. Utility placed to the left of "pipe" is executed first, and its output via STDOUT channel (via handle 0001) is written into this temporary file. Then control is transferred to the utility (or command) placed to the right of "pipe". When this utility issues a request for reception of data via STDIN channel (via handle 0000), these data are taken from the prepared temporary file. When execution of the latter utility terminates, temporary file is automatically deleted.

For example, following command sequence enables to avoid query on whether the user really wants to delete all the files in specified directory :


First an empty temporary file is created. Then the ECHO command is performed, and its output message (a single letter Y) is written into that temporary file. Then the DEL command is executed. Having found the *.* filemask, it issues a request for the user's permission and begins to wait for a reply from STDIN channel. But since its STDIN channel is redirected, execution will not be suspended: the reply – letter Y – will be automatically read at once from the prepared temporary file.

There may be more than two commands linked by "pipes" in one command line. Examples of such command lines are shown in 3.08 and in 3.28.

If the command after the "pipe" sign does not need the contents of temporary file, the command before the "pipe" sign is not obliged to send a message into STDOUT channel. Hence the "pipe" sign can potentially act as a separator, enabling to specify several commands in one line. However, such usage of "pipes" cannot be recommended : the FOR cycle (3.13 ) can do just the same, much faster and without access to a writable disk for creation of temporary file(s).

  1. The "pipe" separator implies creation of a temporary file either in current directory or in the directory, pointed out by environmental variable TEMP. However, both these attempts may fail when DOS is loaded from a non-writable optical disk or from any write-protected media. In such cases an error message informs that the intermediate redirection can't be performed. Then command specified to the right of "pipe" sign will not be executed too.

2.04-06 The "at" ( @ ) sign[edit | edit source]

Being used as the first symbol in batch file's command line, the "at" sign ( @ ) is interpreted as a command to prevent display of this line on the screen. Therefore almost each batch file begins with the "at" sign, followed by the ECHO OFF command. Sometimes such action is necessary not only in the first line (see 3.13, 6.25-02, 6.25-03 for examples).

  1. DOS does not restrict usage of the "at" sign in filenames, but wrong interpretation of filenames with the "at" sign in place of the first letter may lead to harmful consequences.