30

Until now, I never thought (and never observed) that cmd and command are two different things. Well, are they?

Take a look at this pic:

Screenshot of cmd.exe and command.com in 32-bit Windows 7

Actually, I usually open cmd from the Run dialog whenever I want to command-line (for Git/ VIM). So, I customized the display position, font, color, etc. Today, I, for a change, typed command in Run instead of cmd and found that there is something new on my window. It has "DOS" in its window.

So, obviously there should be difference between cmd and command. I would like to know

  1. The difference between them.
  2. Why Microsoft separated them (Unix & Linux has only one shell by default, Bash).
6
  • 12
    I would assume command.com is the legacy 16bit version (only available on 32bit installations). It doesn't exist on my 64bit version of Windows 7. Jul 21, 2012 at 13:34
  • 14
    UNIX and Linux have more than just one shell available. The default shell is typically Bash.
    – ephsmith
    Jul 21, 2012 at 15:02
  • @ephsmith that's what I said..
    – Surya
    Jul 22, 2012 at 3:15
  • Note that the phrase "command prompt" could technically be used to refer to either command.exe or cmd.exe, but in practice is almost always used to mean cmd.exe. Jul 23, 2012 at 5:07
  • Unix has a total of four shell these are csh, ksh, bash, zsh. Jul 23, 2012 at 5:32

3 Answers 3

33

TL;DR

When you run a 32-bit console program, it is executed by cmd; when you run a 16-bit console program, it is executed by command.

Details

Windows XP includes a subsystem to support older 16-bit applications.

Old 16-bit applications are available as both DOS and Windows programs. DOS programs by their nature are console applications and run in what looks like the command-prompt. However 32-bit Windows console applications are very similar and look the same.

The command processor/interpreter cmd has several purposes:

  • To execute 32-bit text Windows console program
  • To provide and handle various command-line functions (dir, copy, etc.)
  • Interpret and execute batch files (DOS compatible .bat files and NT compatible .cmd files)

When you run an old 16-bit console program, it is executed by the NTVDM (Windows NT Virtual DOS Machine). It provides an emulated DOS system (hence the virtual DOS machine) which is similar to running a dedicated virtual machine software, except the emulation layer is simpler. command is a 16-bit version of the command-interpreter that is much closer to actual DOS than cmd.exe which is actually a Windows program (and has the Windows PE header, unlike command.com which has the DOS MZ header).

command has the same purposes as cmd except that it only supports 16-bit programs. In addition, it does not support .cmd files and has fewer built-in commands and is more limited in its syntax (cmd is a newer, more modern, more advanced command-line interpreter, similar to 4DOS).

However, it supports graphical DOS programs (like old games), but the success of running them depends on the video-card drivers and the nature of the program. There are numerous sites that offer various tricks to get DOS games to run on Windows (though success on Vista and up is usually more limited than on XP).

It should be noted that 64-bit versions of Windows have completely dropped support of 16-bit programs, and so do not include command at all, so neither DOS nor Windows 16-bit programs will run and instead will throw a (misleading) error message.


Technical notes

command.com has a .com extension for backwards compatibility with DOS programs, but like most of the other Windows versions of external DOS commands, internally, it is actually a Windows PE .exe file. This provides the interesting observation that while Windows uses the extension as an indicator of how to handle most file-types, for executable ones, it ignores the extension and looks at its contents (otherwise an .exe would not work if treated as a .com). This question relates to this effect.

5
  • 1
    While you can of course run a 32-bit console program from cmd.exe, you don't have to. If you double-click a console-mode executable file, it doesn't run "inside" cmd.exe. Similarly, command.exe isn't really the same thing as the NTVDM. Jul 23, 2012 at 5:05
  • 1
    I hate starting a sentence with a command-name.
    – Synetech
    Jul 23, 2012 at 5:18
  • > command.exe isn't really the same thing as the NTVDM No, but it is a part of it, along with several DLLs (I learned this the hard way while trying to get 16-bit console apps to work on an XP system).
    – Synetech
    Jul 23, 2012 at 14:18
  • "DOS programs by their nature are console applications" – Why would you say this? Are non-command line non-TUI DOS apps 'unnatural' in some way? :)
    – Karan
    Apr 9, 2013 at 21:18
  • Why would you say this? Are non-command line non-TUI DOS apps 'unnatural' in some way? Sort of. In 9x, they were fine, but graphical apps (e.g., games) no longer work properly if at all in XP+, so the vast majority of DOS apps that are run on Windows (natively) these days are indeed command-line tools instead of full-fledge, graphical apps. On 64-bit machines, 16-bit apps don’t run natively at all, but even 32-bit apps are usually console apps, especially since Vista dropped support for fullscreen consoles.
    – Synetech
    Apr 11, 2013 at 15:55
8

Unlike COMMAND.COM, which is a DOS program, cmd.exe is a native Windows application usually running in Win32 console. This allows it to take advantage of features available to native programs on the platform that are otherwise unavailable to DOS programs.

also...

Both the OS/2 and the Windows NT versions of cmd.exe have more detailed error messages than the blanket "Bad command or file name" (in the case of malformed commands) of command.com.

That's from this informative Wikipedia article.

There is mention of how older command.com commands have been rolled into newer cmd.exe functionality... for example...

the functionality of deltree (command.com) was rolled into rd (cmd.exe) in the form of the /s parameter

So, feel free to read up.

1

They're different shells so the syntax and many other things are different. Some good information has been provided in other answers so here is a summary of the syntax differences. For more details read my answer here: Are the Command Prompt and MS-DOS the same thing?

  • command.com doesn't support grouping commands with ()
  • command.com has no functions or local scope
  • command.com doesn't have an escape character which is ^ in cmd.exe
  • command.com doesn't support if cmdextversion and if defined, also no numeric and case-insensitive string comparison if [/i] string1 compare-op string2
  • command.com doesn't have command history and command argument completion
  • command.com doesn't support indirect expansion (e.g. call set %%var%suffix%=string) of variables or delayed expansion (e.g. echo !var%suffix%!)
  • command.com doesn't support advanced string manipulation: no ~xxxV variable, no substring %variable:~num1,num2% or string replacement %variable:str=newstr%
  • The set command in command.com doesn't support partial variable name matching, and no set /a, set /p or set "var=value"
  • command.com doesn't support %* which expand to the whole command line
  • command.com has no for /d, for /r, for /l or for /f
  • command.com doesn't have special environment variables like %CD% %DATE% %TIME% %RANDOM% %ERRORLEVEL% %CMDEXTVERSION% %CMDCMDLINE% %HIGHESTNUMANODENUMBER%
  • command.com doesn't have pushd/popd or cd /d. And obviously it doesn't support cd path with spaces and cd "path with spaces" like cmd.exe
  • command.com doesn't have the color or title command

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .