COMMAND.COM is DOS' 16-bits command interpreter. Without it, DOS couldn't execute the commands you type, nor the ones you put in batch files.
In MS-DOS (including Windows 9x) and PC-DOS, COMMAND.COM is loaded at boot time, through the SHELL statement in CONFIG.SYS. This primary command interpreter will always stay in memory, until the computer is shut down (though part of it may sometimes be "overwritten" in memory, to give programs some extra memory space; this "transient" part of COMMAND.COM will then be reloaded after the program has been closed).
You may, however, "nest" as many secondary (and more) COMMAND.COMs as is practically possible within the 640KB memory constraints. These secondary command processors will usually be closed after executing one or more commands in their own copy of DOS' environment.
|Note:||COMMAND.COM is the only native command interpreter in MS-DOS (including Windows 9x) and PC-DOS.
In Windows NT 4/2000/XP/Server 2003/Vista and in OS/2, CMD.EXE is the default 32-bits command interpreter; a 16-bits COMMAND.COM emulation is available for compatibility purposes, however.
|drive:path||Location of COMMAND.COM||May also be set by the second parameter of the SHELL command|
|device||Device to be used for command input and output (default is CON)||Valid devices: PRN, LPT1..3, CON, AUX, COM1..4, NUL|
|/C||Close secondary session after execution of string||Also called Child process|
|/D||AUTOEXEC.BAT not executed||MS-DOS 6+|
|/E:nnn||Environment size in bytes||Minimum value for n is 160 bytes, maximum is 32768, values outside this range are ignored|
|/F||Fail by default (no more "Abort, Retry, Fail?" messages)||MS-DOS 6+, OS/2 Warp 4 DOS box|
|/K||Keep secondary session, do not close session after execution of command_string||Use
|/MSG||Message files in memory||Valid with /P only; to be used when booting from removable disk|
|/P||Permanent in memory||Also called Parent or Primary process; COMMAND.COM cannot be
removed from memory using
|/Y||Debug switch, step through batch files one step at a time||MS-DOS 6+|
|/Z||Display the errorlevel of every (external) command executed||MS-DOS 7.* (Windows 95/98)|
|command_string||Command string to be executed by COMMAND.COM|
Use the /F parameter to check if a removable drive is ready:
COMMAND /F /C DIR F:\ | FIND "F:" > NUL IF ERRORLEVEL 1 ECHO Drive F: is not ready IF NOT ERRORLEVEL 1 ECHO Drive F: is ready
The batch file above will still give an error message if drive F: is not ready, but will not wait for user interaction.
One way to get rid of the error message could be to nest several batch files.
If you would call the batch file above with:
COMMAND NUL /C previous.bat
the error message would be redirected to NUL (and so would the ECHOed message).
COMMAND NUL /C ....
gives the same results as
However, CTTY is not a standard part of "modern" Microsoft operating systems anymore, whereas COMMAND.COM still is. It is not possible to replace COMMAND with %COMSPEC%, since this trick will not work with other command processors than COMMAND.COM.
The example shown above depends on MS-DOS 6's FIND returning an errorlevel if it doesn't find the specified string. This will not work in older DOS versions or in OS/2 Warp's DOS box, though, since FIND won't return errorlevels in those DOS versions.
The following batch file does work in OS/2 and should most likely work in MS-DOS 5 and 6 too, except redirection of Standard Error (2>). It will not work in MS-DOS 7 (Windows 95/98), however, since it also depends on the fact that COPY didn't copy 0 byte files and didn't give an error message in pre-MS-DOS 7 versions.
@ECHO OFF :: DRIVEReaDY — Check if drive A: is ready :: Written by Rob van der Woude :: Dependencies: Needs MS-DOS 6 or up, or OS/2 Warp 4 :: May or may not work on earlier OS versions, :: that hasn't been tested yet :: :: Set initial value SET AREADY= :: Clean up old temporary files IF EXIST DRIVERDY.DAT DEL DRIVERDY.DAT IF EXIST DRIVERDY.TMP DEL DRIVERDY.TMP :: Check if drive A: is ready, redirect error message to temporary :: file, /F parameter automates "Fail" on Abort, Retry, Fail prompt COMMAND.COM /F /C DIR A: 1> NUL 2> DRIVERDY.DAT :: Copy temporary file; if zero bytes, copy will fail without error IF EXIST DRIVERDY.DAT COPY DRIVERDY.DAT DRIVERDY.TMP 1> NUL 2> NUL IF EXIST DRIVERDY.TMP SET AREADY= NOT :: Clean up temporary files IF EXIST DRIVERDY.DAT DEL DRIVERDY.DAT IF EXIST DRIVERDY.TMP DEL DRIVERDY.TMP :: Display result ECHO Drive A: is%AREADY% ready
When using secondary (or more) command interpreters, keep in mind that:
SHELL=C:\DOS\COMMAND.COM C:\DOS /E:512 /P
In CONFIG.SYS the SHELL command is used to specify the primary command processor (C:\DOS\COMMAND.COM), the path to COMMAND.COM (C:\DOS, needed to reload the "transient" part of COMMAND.COM), the environment size in bytes (/E:512), and finally the /P parameter makes the primary command interpreter permanent (without the /P parameter, it would be possible to remove the primary command interpreter from memory by using the EXIT command, thus leaving the operating system without command interpreter and without the means to reload it).
You may add any parameter that is valid for the specified command interpreter.
In MS-DOS 5 and up, it is possible to load the primary command interpreter in high memory:
SHELL=C:\DOS\COMMAND.COM /C LH C:\DOS\COMMAND.COM /E:512 /P
This can be done by not making the primary command interpreter permanent (/C instead of /P parameter) and instead loading a second command processor high and make it permanent.
You will need to add
DOS=HIGH to your CONFIG.SYS, of course.
COMSPEC specifies the secondary command interpreter.
This need not be COMMAND.COM.
One example of a different command interpreter is JP Software's 4DOS.COM.
COMMAND /C with
%COMSPEC% /C if you do not know for sure which command interpreter will be used.
page last uploaded: 2019-02-21, 09:59