[Toc][Index]

Executable Files and File Searches


Once CMD.EXE knows that it is supposed to run an external command, it 
tries to find an executable file (one with a .COM or .EXE extension) whose 
name matches the command name.  It runs the executable file if it finds 
one. 
If CMD.EXE cannot find an executable program to run, it next looks for a 
batch file (a file with one or more commands in it) whose name matches the 
command name.  CMD.EXE looks first for a .BTM file, then for a .CMD file, 
then for a .BAT file, and finally for a .REX file.  See .BAT, .CMD, and 
.BTM Files for more information on these different types of batch files. 
 If CMD.EXE finds such a file, it then reads each line in the file as a 
new command. 
If the search for a batch file fails, CMD.EXE checks to see if the command 
name matches the name of a file with an extension that is associated with 
a specific application (for example, if you have associated .DOC with your 
editor or word processor, and you type the name of a .DOC file).  If a 
match is found, CMD.EXE runs the program you specified when the 
association was defined. 
In searching for the application associated with a file, CMD.EXE will 
first examine any executable extensions you have defined to associate a 
file extension with a specific program to process that type of file. 
CMD.EXE first searches for an executable program, a batch file, and a file 
with an executable extension in the current directory.  If the command 
name doesn't match a .COM, .EXE, .BTM, .BAT or .CMD file or an executable 
extension in the current directory, CMD.EXE repeats its search in every 
directory in your search path. 
The search path is a list of directories that CMD.EXE (and some 
applications) search for executable files.  For example, if you wanted 
CMD.EXE to search the root directory of the C: drive, the \OS2 
subdirectory on the C: drive, and the \UTIL directory on the D: drive for 
executable files, your search path would look like this: 


        PATH=C:\;C:\OS2;D:\UTIL

Notice that the directory names in the search path are separated by 
semicolons. 
You can create or view the search path with the PATH command.  You can use 
the ESET command to edit the path.  Many programs also use the search path 
to find their own files.  The search path is stored in the environment 
with the name PATH. 
Remember, CMD.EXE always looks for an executable file or a file with an 
executable extension in the current subdirectory, then in each directory 
in the search path.  (You can change the search order so the current 
directory is not searched first; see the PATH command for details.) 
If you include an extension as part of the command name, CMD.EXE only 
searches for a file with that extension.  Similarly, if you include a path 
as part of the command name, the command processor will look only in the 
directory you specified, and ignore the usual search of the current 
directory and the PATH. 
The following table sums up the possible search options (the term 
"standard search" refers to the search of the current directory and each 
directory in the search path): 
        Command                 CMD.EXE Search Sequence 
        WP                      Standard search for any executable file 
                                whose base name is WP. 
        WP.EXE                  Standard search for WP.EXE; will not find 
                                files with other extensions. 
        C:\WP7\WP               Looks in the C:\WP7 directory for any 
                                executable file whose base name is WP. 
                                 Does not check the standard search 
                                directories. 
        C:\WP7\WP.EXE           Looks only for the file C:\WP7\WP.EXE. 
        LAB.DOC                 Standard search for LAB.DOC, if .DOC is 
                                defined as an executable extension.  Runs 
                                the associated application if the file is 
                                found. 
        C:\LI\LAB.DOC           Looks only for the file C:\LI\LAB.DOC, and 
                                only if .DOC is defined as an executable 
                                extension.  Runs the associated 
                                application if the file is found. 
 
 If CMD.EXE cannot find an executable file, batch program, or a file with 
 an executable extension in the current directory or any directory in the 
 search path, it looks for an alias called UNKNOWN_CMD (see the ALIAS 
 command for details).  If you have defined an alias with that name, it is 
 executed (this allows you to control error handling for unknown 
 commands).  Otherwise, CMD.EXE displays an "Unknown command" error 
 message and waits for your next instruction. 

Created using Inf-PHP v.2 (c) 2003 Yuri Prokushev
Created using Inf-HTML v.0.9b (c) 1995 Peter Childs