Order of Precedence in Locating Executable Files

This article was previously published under Q35284
This article has been archived. It is offered "as is" and will no longer be updated.
SUMMARY
This article discusses the following:

  • How COMMAND.COM finds executable files
  • The order of precedence involved in this search
  • How the order can be overridden in MS-DOS versions 4.x and later
  • The difference in filename recognition between COMMAND.COM and the MS-DOS EXEC system call
MORE INFORMATION

COMMAND.COM

COMMAND.COM can execute a file typed on the command line or as a line in abatch file.

MS-DOS Versions Earlier Than Version 4.0

When a filename is given, whether or not an extension is supplied,COMMAND.COM keeps the base name only. (COMMAND.COM removes the filenameextension if one exists [for example, "FILE" remains if the filename is"FILE.EXE"]). After it has the base name, COMMAND.COM looks in thefollowing order for an executable file that has this name:
   .COM  .EXE  .BAT				
If COMMAND.COM cannot find this file in the current directory of thecurrent drive, it begins searching the directories specified in the PATHenvironment variable in the AUTOEXEC.BAT file. If such a file is not found,the following error message is displayed:
Bad command or file name
For example, if there are three files in the current directory: FILE.COM,FILE.EXE, and FILE.BAT, and you try to execute any one of them by typingFILE.COM, FILE.EXE, FILE.BAT, or FILE, COMMAND.COM executes only FILE.COM, because this is the first fileit finds.

MS-DOS Versions 4.0 and Later

In MS-DOS versions 4.0 and later, you can override the COM-EXE-BATprecedence by typing the command with the extension.

For example, if there are three files in the current directory: FILE.COM,FILE.EXE, and FILE.BAT, and you try to execute any one of them by typingFILE.COM, FILE.EXE, or FILE.BAT,COMMAND.COM executes the one you specify. However, if no filename extensionis given, the usual order of precedence is used (.COM, .EXE, and .BAT).

One side effect of this behavior is that some incorrect or expedient waysof executing files no longer work. For example, in versions of MS-DOSearlier than 4.0, you can execute FILE.BAT by typing the filename with aperiod following it FILE.. However, in MS-DOS 4.0 and later, if youtype FILE., MS-DOS searches for a file bythis name, cannot find one, and returns a "bad command or file name" errormessage.

MS-DOS Versions 5.0 and Later

MS-DOS versions 5.0 and later search for files in the following order:
   DOSKEY Macro  .COM  .EXE  .BAT				
For example, if there are three files in the current directory: FILE.COM,FILE.EXE, and FILE.BAT, and there is also a DOSKEY macro named FILE, themacro is given precedence and executed when FILE is run from the commandline of the current directory. This is not true in earlier versions ofMS-DOS, as there was no DOSKEY macro feature.

Also, in MS-DOS versions 5.0 and later, DOSKEY macros have precedence overinternal commands. To override a DOSKEY macro, type one or more spacesbefore the command.

EXEC Function

The MS-DOS EXEC function (interrupt 21h service 4Bh) does not understandfilename extensions; therefore, it simply takes the name of the filespecified when invoked and tries to execute it.

This lack of filename information is an advantage to programs that havefiles that are executable. Such files are device drivers (which normallyhave the extension .SYS) or overlay files (which normally have theextension .OVL). COMMAND.COM cannot execute these files; only programs thatexplicitly call the EXEC function can run such programs.

The EXEC function understands only the files that in most cases have .COMand .EXE extensions. It is not able to execute .BAT files; these files arespecifically "executed", one line at a time, by COMMAND.COM.
6.22 4.00 4.00a 4.01 4.01a 5.00 5.00a 6.00 6.20
Properties

Article ID: 35284 - Last Review: 12/04/2015 09:02:54 - Revision: 2.0

Microsoft MS-DOS 4.0 Standard Edition, Microsoft MS-DOS 4.01 Standard Edition, Microsoft MS-DOS 5.0 Standard Edition, Microsoft MS-DOS 5.0a, Microsoft MS-DOS 6.0 Standard Edition, Microsoft MS-DOS 6.2 Standard Edition, Microsoft MS-DOS 6.21 Standard Edition, Microsoft MS-DOS 6.22 Standard Edition

  • kbnosurvey kbarchive KB35284
Feedback