Menu
Home Explore People Places Arts History Plants & Animals Science Life & Culture Technology
On this page
cmd.exe
Shell for Windows NT and other operating systems

cmd.exe, or Command Prompt, is a shell program used in later versions of Windows (including NT and CE), as well as in OS/2, eComStation, ArcaOS, and ReactOS. It replaced COMMAND.COM, the shell used in older systems like DOS and Windows 9x. The ReactOS version is based on FreeCOM, the FreeDOS interpreter. Windows now offers PowerShell alongside cmd.exe as an advanced alternative shell. Initial development of cmd.exe for Windows NT was by Therese Stowell, and embedded Windows CE versions first supported it starting with Windows CE 2.11. Despite platform differences, cmd.exe maintains consistent behavior and commands across systems.

Related Image Collections Add Image
We don't have any YouTube videos related to cmd.exe yet.
We don't have any PDF documents related to cmd.exe yet.
We don't have any Books related to cmd.exe yet.
We don't have any archived web articles related to cmd.exe yet.

Use

Desktop integration

In Windows, the shell is presented in the desktop via Windows Terminal or on older versions via Windows Console.

Concurrent piping

In OS/2 and Windows, the shell supports pipes to allow both sides of a pipeline to run concurrently. As a result, it is possible to redirect the standard error stream. In contrast, COMMAND.COM uses temporary files, and runs the two sides serially, one after the other.

Command separator

Multiple commands can be included in a single line using the command separator & or &&.9

With the & separator, a subsequent command is executed even if the previous command indicates an error.10 In the following example, each of the three commands is executed, one after the other, and regardless of their result code.

>CommandA & CommandB & CommandC

With the && separator, a command must complete successfully for the subsequent command to execute. In the following example, CommandB only executes if CommandA completes successfully, and CommandC only executes if CommandB also completes successfully.

>CommandA && CommandB && CommandC

Command line limit

The shell limits the length of a command line which includes entered text, individual environment variables that are inherited by other processes, and all environment variable expansions11 On Windows XP and later, the maximum length is 8191 (213-1) characters. On earlier versions, such as Windows 2000 or Windows NT 4.0, the maximum length is 2047 (211-1) characters.

Escaping special characters

The shell reserves the following characters as special:12 &<>[]{}^=;!'+,`~ and whitespace. In some cases, an argument that contains such characters must be enclosed in double quotes to escape from the special character handling. For example:

>echo me & you me 'you' is not recognized as an internal or external command, operable program or batch file. >echo "me & you" "me & you"

Internal commands

The following sections list internal commands for implementations of the shell on various operating systems.

OS/2

Internal commands in OS/2:13

Windows NT family

Internal commands in Windows NT and later:14

Windows CE

Internal commands in Windows CE .NET 4.2,15 Windows CE 5.016 and Windows Embedded CE 6.0:17

  • attrib
  • call
  • cd
  • chdir
  • cls
  • copy
  • date
  • del
  • dir
  • echo
  • erase
  • exit
  • goto
  • help
  • if
  • md
  • mkdir
  • move
  • path
  • pause
  • prompt
  • pwd
  • rd
  • rem
  • ren
  • rename
  • rmdir
  • set
  • shift
  • start
  • time
  • title
  • type

The net command is available as an external command.

ReactOS

Internal commands in ReactOS:18

  • ?
  • alias
  • assoc
  • beep
  • call
  • cd
  • chdir
  • choice
  • cls
  • color
  • copy
  • ctty
  • date
  • del
  • delete
  • delay
  • dir
  • dirs
  • echo
  • echos
  • echoerr
  • echoserr
  • endlocal
  • erase
  • exit
  • for
  • free
  • goto
  • history
  • if
  • memory
  • md
  • mkdir
  • mklink
  • move
  • path
  • pause
  • popd
  • prompt
  • pushd
  • rd
  • rmdir
  • rem
  • ren
  • rename
  • replace
  • screen
  • set
  • setlocal
  • shift
  • start
  • time
  • timer
  • title
  • type
  • ver
  • verify
  • vol

Comparison with COMMAND.COM

On Windows, cmd.exe provides various user experience enhancments as compared to COMMAND.COM, including:

  • More detailed error reporting for malformed commands than the generic COMMAND.COM "Bad command or file name". In OS/2, errors are reported in the chosen language of the system, their text being taken from the system message files. The HELP command can then be issued with the error message number to obtain further information.
  • Supports using of arrow keys to scroll through command history. With COMMAND.COM, this functionality was only available in DR DOS; via HISTORY) and later via an external component called DOSKEY.
  • Adds rotating command-line completion for file and folder paths, where the user can cycle through results for the prefix using the Tab ↹, and ⇧ Shift+Tab ↹ for reverse direction.
  • Treats the caret character (^) as the escape character; the character following it is to be taken literally. There are special characters in cmd.exe and COMMAND.COM that are meant to alter the behavior of the command line processor. The caret character forces the command line processor to interpret them literally.
  • Supports delayed variable expansion with SETLOCAL EnableDelayedExpansion, allowing values of variables to be calculated at runtime instead of during parsing of script before execution (Windows 2000 and later), fixing DOS idioms that made using control structures hard and complex.19 The extensions can be disabled, providing a stricter compatibility mode.
  • The COMMAND.COM DELTREE command was merged into the rd command via the /S switch.
  • SetLocal and EndLocal commands limit the scope of changes to the environment. Changes made to the command line environment after SetLocal are local to the batch file. EndLocal restores the previous settings.20
  • The call command allows subroutines within batch file. The COMMAND.COM CALL command only supports calling external batch files.
  • File name parser extensions to the set command are comparable with C shell.
  • The set command can perform expression evaluation.
  • An expansion of the for command supports parsing files and arbitrary sets in addition to file names.
  • The new pushd and popd commands provide access past navigated paths similar to forward and back buttons in a web browser or File Explorer.
  • The conditional if command can perform case-insensitive comparisons and numeric equality and inequality comparisons in addition to case-sensitive string comparisons. This was available in DR-DOS, but not in PC DOS or MS-DOS.

See also

Further reading

  • David Moskowitz; David Kerr (1994). OS/2 2.11 Unleashed (2nd ed.). Sams Publishing. ISBN 978-0672304453.
  • Stanek, William R. (2008). Windows Command-Line Administrator's Pocket Consultant (2nd ed.). Microsoft Press. ISBN 978-0735622623.
Wikimedia Commons has media related to Windows Command Prompt. Wikibooks has a book on the topic of: Windows Batch Scripting

References

  1. "Notes on using the default OS/2 command processor (CMD.EXE)". www.tavi.co.uk. http://www.tavi.co.uk/os2pages/cmd.html

  2. "reactos/reactos". GitHub. December 4, 2021. https://github.com/reactos/reactos

  3. "Command Processor Shell (Windows CE .NET 4.2)". Microsoft Docs. June 30, 2006. Archived from the original on August 31, 2022. https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ms879823(v%3dmsdn.10)

  4. "Command Processor Shell (Windows CE 5.0)". Microsoft Docs. September 14, 2012. Archived from the original on August 28, 2022. https://docs.microsoft.com/en-us/previous-versions/windows/embedded/aa453925(v%3dmsdn.10)

  5. "Command Processor Shell (Windows Embedded CE 6.0)". Microsoft Docs. 2012. Archived from the original on September 5, 2022. https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ee499728(v%3dwinembedded.60)

  6. Zachary, G. Pascal (1994). Showstopper! The Breakneck Race to Create Windows NT and the Next Generation at Microsoft. The Free Press. ISBN 0-02-935671-7. 0-02-935671-7

  7. Douglas McConnaughey Boling (2001). Programming Microsoft Windows CE (2nd ed.). Microsoft Press. ISBN 978-0735614437. 978-0735614437

  8. "reactos/reactos". GitHub. December 4, 2021. https://github.com/reactos/reactos

  9. "cmd". Microsoft Learn. September 12, 2023. Archived from the original on November 21, 2023. https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/cmd

  10. "Command Redirection, Pipes - Windows CMD - SS64.com". ss64.com. Retrieved September 23, 2021. https://ss64.com/nt/syntax-redirection.html

  11. Command prompt (Cmd.exe) command-line string limitation https://support.microsoft.com/en-us/help/830473/command-prompt-cmd-exe-command-line-string-limitation

  12. "cmd". Microsoft Learn. September 12, 2023. Archived from the original on November 21, 2023. https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/cmd

  13. Microsoft Operating System/2 User's Reference (PDF). Microsoft. 1987. http://www.os2museum.com/wp/wp-content/uploads/2011/12/1987-Oct-OS2-1.0-Users_Reference.pdf

  14. Hill, Tim (1998). Windows NT Shell Scripting. Macmillan Technical Publishing. ISBN 978-1578700479. 978-1578700479

  15. "Command Processor Commands (Windows CE .NET 4.2)". Microsoft Docs. June 30, 2006. Archived from the original on August 31, 2022. https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ms879786(v=msdn.10)

  16. "Command Processor Commands (Windows CE 5.0)". Microsoft Docs. September 14, 2012. Archived from the original on August 31, 2022. https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ms907227(v=msdn.10)

  17. "Command Processor Commands (Windows Embedded CE 6.0)". Microsoft Docs. January 5, 2012. Archived from the original on September 6, 2022. https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ee505427(v=winembedded.60)

  18. "reactos/reactos". GitHub. December 4, 2021. https://github.com/reactos/reactos

  19. "Windows 2000 delayed environment variable expansion". Windows IT Pro. Archived from the original on July 13, 2015. Retrieved July 13, 2015. https://web.archive.org/web/20150713131827/http://windowsitpro.com/windows/jsi-tip-3240-windows-2000-delayed-environment-variable-expansion

  20. "Setlocal". TechNet. Microsoft. September 11, 2009. Retrieved January 13, 2015. https://technet.microsoft.com/en-us/library/bb491001.aspx