{{short description|Shell for Windows NT and other operating systems}} {{distinguish|COMMAND.COM}} {{Other uses|CMD (disambiguation){{!}}CMD}} {{Redirect|Command Prompt|the concept|Command prompt}} {{Lowercase title}} {{use mdy dates|date=January 2024}} {{Infobox software | name = Command Prompt ({{mono|cmd.exe}}) | logo = Command prompt icon (windows).png | logo_size = 48px | screenshot = | screenshot_size = 100px | caption = Command Prompt in Windows 11 | developer = Microsoft, IBM, ReactOS contributors | released = {{Start date and age|1987|12}} | other_names = Windows Command Processor | replaces = COMMAND.COM | operating system = {{Plainlist| * Windows NT family * Windows CE family * OS/2 * eComStation * ArcaOS * ReactOS}} | platform = IA-32, x86-64, ARM (and historically DEC Alpha, MIPS, PowerPC, and Itanium) | genre = Command-line interpreter }} '''{{mono|cmd.exe}}''', also known as '''Command Prompt''' or '''Windows Command Processor''', is a shell program on later versions of Windows (NT and CE families), OS/2,<ref>{{Cite web|url=http://www.tavi.co.uk/os2pages/cmd.html|title=Notes on using the default OS/2 command processor (CMD.EXE)|website=www.tavi.co.uk}}</ref> eComStation, ArcaOS, and ReactOS.<ref name="ReactOS" /> In some versions of Windows (CE .NET 4.2,<ref>{{Cite web|url=https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ms879823(v%3dmsdn.10)|title=Command Processor Shell (Windows CE .NET 4.2)|website=Microsoft Docs |date=June 30, 2006 |url-status=live |archive-url=https://web.archive.org/web/20220831154120/https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ms879823(v%3dmsdn.10) |archive-date=August 31, 2022}}</ref> CE 5.0<ref>{{Cite web|url=https://docs.microsoft.com/en-us/previous-versions/windows/embedded/aa453925(v%3dmsdn.10)|title=Command Processor Shell (Windows CE 5.0)|website=Microsoft Docs |date=September 14, 2012 |url-status=live |archive-url=https://web.archive.org/web/20220828195757/https://docs.microsoft.com/en-us/previous-versions/windows/embedded/aa453925(v%3dmsdn.10) |archive-date=August 28, 2022}}</ref> and Embedded CE 6.0<ref>{{Cite web|url=https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ee499728(v%3dwinembedded.60)|title=Command Processor Shell (Windows Embedded CE 6.0)|website=Microsoft Docs |date=2012 |url-status=live |archive-url=https://web.archive.org/web/20220905191436/https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ee499728(v%3dwinembedded.60) |archive-date=September 5, 2022}}</ref>) it is referred to as the '''Command Processor Shell'''. Implementation differs between operating systems, but with significant consistency of behavior and available commands.
Older, related operating systems, DOS and Windows 9x, provided {{mono|COMMAND.COM}} as the shell. {{mono|cmd.exe}} replaced {{mono|COMMAND.COM}} in the Windows product line with the introduction of NT. Current versions of Windows include PowerShell as an alternative shell that runs side-by-side with {{mono|cmd.exe}}.
The initial version of {{mono|cmd.exe}} for Windows NT was developed by Therese Stowell.<ref name="Zachary_1994">{{Cite book |title=Showstopper! The Breakneck Race to Create Windows NT and the Next Generation at Microsoft |author-first=G. Pascal |author-last=Zachary |date=1994 |publisher=The Free Press |isbn=0-02-935671-7 |url-access=registration |url=https://archive.org/details/showstopperbreak00zach}}</ref> Windows CE 2.11 was the first embedded Windows release to support a console and a Windows CE version of {{mono|cmd.exe}}.<ref>{{Cite book|author=Douglas McConnaughey Boling|year=2001|title=Programming Microsoft Windows CE|edition=2nd|publisher=Microsoft Press|isbn=978-0735614437}}</ref> The ReactOS implementation of {{mono|cmd.exe}} is derived from FreeCOM, the FreeDOS command line interpreter.<ref name="ReactOS" />
==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, {{mono|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 separators {{code|&}}, {{code|&&}} or <code>||</code>.<ref name="docs.microsoft.com">{{Cite web|url=https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/cmd|title=cmd|website=Microsoft Learn |date=September 12, 2023 |url-status=live |archive-url=https://web.archive.org/web/20231121065635/https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/cmd |archive-date=November 21, 2023}}</ref>
With the {{code|&}} separator, a subsequent command is executed even if the previous command indicates an error.<ref>{{Cite web|title=Command shell overview|url=https://technet.microsoft.com/en-us/library/cc737438.aspx|access-date=2026-02-22|website=Microsoft TechNet}}</ref> In the following example, each of the three commands is executed, one after the other, and regardless of their exit code.
<syntaxhighlight lang="doscon"> >CommandA & CommandB & CommandC </syntaxhighlight>
With the {{code|&&}} separator, a command must succeed, i.e. yield the exit code 0, for the subsequent command to execute. In the following example, {{code|CommandB}} only executes if {{code|CommandA}} completes successfully, and {{code|CommandC}} only executes if {{code|CommandB}} also completes successfully.
<syntaxhighlight lang="doscon"> >CommandA && CommandB && CommandC </syntaxhighlight>
With the <code>||</code> separator, a command must fail, i.e. yield an exit code not equal 0, for the subsequent command to execute. In the following example, {{code|CommandB}} executes if {{code|CommandA}} fails, and {{code|CommandC}} executes if {{code|CommandB}} succeeds.
<syntaxhighlight lang="doscon"> >CommandA || CommandB && CommandC </syntaxhighlight>
===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 expansions<ref>[https://support.microsoft.com/en-us/help/830473/command-prompt-cmd-exe-command-line-string-limitation Command prompt (Cmd.exe) command-line string limitation]</ref> On Windows XP and later, the maximum length is 8191 (2<sup>13</sup>-1) characters. On earlier versions, such as Windows 2000 or Windows NT 4.0, the maximum length is 2047 (2<sup>11</sup>-1) characters.
===Escaping special characters=== The shell reserves the following characters as special:<ref name="docs.microsoft.com"/> <code>&<>[]{}^=;!'+,`~</code> 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:
<syntaxhighlight lang="doscon">>echo me & you me 'you' is not recognized as an internal or external command, operable program or batch file.
>echo "me & you" "me & you" </syntaxhighlight>
==Internal commands==
The following sections list internal commands for implementations of the shell on various operating systems.
===OS/2=== thumb|{{mono|cmd.exe}} running in '''OS/2 Window''' on OS/2 version 1.3
Internal commands in OS/2:<ref>{{Cite book|title=Microsoft Operating System/2 User's Reference|date=1987|publisher=Microsoft|url=http://www.os2museum.com/wp/wp-content/uploads/2011/12/1987-Oct-OS2-1.0-Users_Reference.pdf}}</ref>
{{Div col|colwidth=6em}} * break * chcp * cd * chdir * cls * copy * date * del * detach * dir * dpath * echo * erase * exit * for * goto * if * md * mkdir * path * pause * prompt * rd * rem * ren * rename * rmdir * set * shift * start * time * type * ver * verify * vol {{Div col end}}
===Windows NT family=== [[File:Windows11Terminal uk.png|thumb|{{mono|cmd.exe}} running in '''Windows Terminal''' on Ukrainian Windows 11]]
Internal commands in Windows NT and later:<ref>{{Cite book|author-last=Hill|author-first=Tim|title=Windows NT Shell Scripting|date=1998|publisher=Macmillan Technical Publishing|isbn=978-1578700479|url-access=registration|url=https://archive.org/details/windowsntshellsc0000hill}}</ref>
{{Div col|colwidth=6em}} * assoc * break * call * cd * chdir * cls * color * copy * date * del * dir * dpath * echo * endlocal * erase * exit * for * ftype * goto * if * keys * md * mkdir * mklink * move * path * pause * popd * prompt * pushd * rd * rem * ren * rename * rmdir * set * setlocal * shift * start * time * title * type * ver * verify * vol {{Div col end}}
===Windows CE=== [[File:Microsoft Windows CE Version 3.0 (Build 126) cmd.exe Command Prompt 800x574.png|thumb|Pocket CMD v 3.0 (cmd.exe) on Windows CE 3.0]]
Internal commands in Windows CE .NET 4.2,<ref>{{Cite web|url=https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ms879786(v=msdn.10)|title=Command Processor Commands (Windows CE .NET 4.2)|website=Microsoft Docs |date=June 30, 2006 |url-status=live |archive-url=https://web.archive.org/web/20220831154120/https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ms879786(v=msdn.10) |archive-date=August 31, 2022}}</ref> Windows CE 5.0<ref>{{Cite web|url=https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ms907227(v=msdn.10)|title=Command Processor Commands (Windows CE 5.0)|website=Microsoft Docs |date=September 14, 2012 |url-status=live |archive-url=https://web.archive.org/web/20220831150618/https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ms907227(v=msdn.10) |archive-date=August 31, 2022}}</ref> and Windows Embedded CE 6.0:<ref>{{Cite web|url=https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ee505427(v=winembedded.60)|title=Command Processor Commands (Windows Embedded CE 6.0)|website=Microsoft Docs |date=January 5, 2012 |url-status=live |archive-url=https://web.archive.org/web/20220906020659/https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ee505427(v=winembedded.60) |archive-date=September 6, 2022}}</ref>
{{Div col|colwidth=6em}} * 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 {{Div col end}}
The {{mono|net}} command is available as an external command.
===ReactOS=== thumb|{{mono|cmd.exe}} on ReactOS
Internal commands in ReactOS:<ref name="ReactOS">{{Cite web|url=https://github.com/reactos/reactos |title=reactos/reactos |website=GitHub |date=December 4, 2021}}</ref>
{{Div col|colwidth=6em}} * ? * alias * assoc * beep * call * cd * chdir * choice * cls * color * copy * ctty * date * del * delete * delay * dir * dirs * echo * echos * {{not a typo|echoerr}} * {{not a typo|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 {{Div col end}}
==Comparison with COMMAND.COM== On Windows, {{mono|cmd.exe}} provides various user experience enhancements as compared to {{mono|COMMAND.COM}}, including:
* More detailed error reporting for malformed commands than the generic {{mono|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 <code>HELP</code> 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 {{mono|COMMAND.COM}}, this functionality was only available in DR DOS (via HISTORY) and later via an external component called {{mono|DOSKEY}}. * Adds rotating command-line completion for file and folder paths, where the user can cycle through results for the prefix using the {{keypress|tab}}, and {{keypress|Shift|Tab}} for reverse direction. * Treats the caret character ({{mono|^}}) as the escape character; the character following it is to be taken literally. There are special characters in {{mono|cmd.exe}} and {{mono|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 {{code|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.<ref name="Delay"/> The extensions can be disabled, providing a stricter compatibility mode. * The {{mono|COMMAND.COM}} <code>DELTREE</code> command was merged into the <code>rd</code> command via the {{code|/S}} switch. * {{code|SetLocal}} and {{code|EndLocal}} commands limit the scope of changes to the environment. Changes made to the command line environment after {{code|SetLocal}} are local to the batch file. {{code|EndLocal}} restores the previous settings.<ref name="SetLocal"/> * The {{code|call}} command allows subroutines within batch file. The {{mono|COMMAND.COM}} {{code|CALL}} command only supports calling external batch files. * File name parser extensions to the {{code|set}} command are comparable with C shell.{{Explain|reason=|date=October 2015}} * The {{code|set}} command can perform expression evaluation. * An expansion of the <code>for</code> command supports parsing files and arbitrary sets in addition to file names. * The new <code>pushd</code> and <code>popd</code> commands provide access past navigated paths similar to forward and back buttons in a web browser or File Explorer. * The conditional {{code|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== * {{Annotated link|Comparison of command shells}} * {{Annotated link|List of DOS commands}}
==References== {{Reflist|refs= <!-- <ref name="Zachary_1994">{{Cite book |title=Showstopper! The Breakneck Race to Create Windows NT and the Next Generation at Microsoft |author-first=G. Pascal |author-last=Zachary |date=1994 |publisher=The Free Press |isbn=0-02-935671-7 |url-access=registration |url=https://archive.org/details/showstopperbreak00zach}}</ref> --> <ref name="Delay">{{Cite web |title=Windows 2000 delayed environment variable expansion |work=Windows IT Pro |url=http://windowsitpro.com/windows/jsi-tip-3240-windows-2000-delayed-environment-variable-expansion |access-date=2015-07-13 |archive-url=https://web.archive.org/web/20150713131827/http://windowsitpro.com/windows/jsi-tip-3240-windows-2000-delayed-environment-variable-expansion |archive-date=2015-07-13 |url-status=dead}}</ref> <ref name="SetLocal">{{Cite web |title=Setlocal |work=TechNet |date=September 11, 2009 |publisher=Microsoft |url=https://technet.microsoft.com/en-us/library/bb491001.aspx |access-date=2015-01-13}}</ref> }}
==Further reading== * {{Cite book|author1=David Moskowitz|author2=David Kerr|year=1994|title=OS/2 2.11 Unleashed|edition=2nd|publisher=Sams Publishing|isbn=978-0672304453|ref=none}} * {{Cite book|first=William R.|last=Stanek|year=2008|title=Windows Command-Line Administrator's Pocket Consultant|edition=2nd|publisher=Microsoft Press|isbn=978-0735622623|ref=none}}
==External links== {{Commons category|Windows Command Prompt}} {{Wikibooks|Windows Batch Scripting}}
* {{Cite web|url=https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/windows-commands|title=Command-line reference A-Z|date=April 26, 2023 |publisher=Microsoft}} * {{Cite web |url=http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx |title=Cmd |publisher=Microsoft |work=Microsoft Windows XP Product Documentation |access-date=2006-05-24 |archive-url=https://web.archive.org/web/20110902070525/http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx |archive-date=2011-09-02 |url-status=dead}} * {{Cite web |url=http://windows.microsoft.com/en-us/windows/command-prompt-faq#1TC=windows-7 |title=Command Prompt: frequently asked questions |publisher=Microsoft |work=windows Help |access-date=2015-04-20 |archive-url=https://web.archive.org/web/20150422041137/http://windows.microsoft.com/en-us/windows/command-prompt-faq#1TC=windows-7 |archive-date=2015-04-22 |url-status=dead}} * {{Cite web |url=https://ss64.com/nt/ |title=An A–Z Index of the Windows CMD command line |publisher=SS64.com}} * {{Cite web |url=https://windowscmd.com/ |title=Windows CMD.com – Hub of Windows Commands |publisher=windowscmd.com |access-date=2022-01-04 |archive-date=2022-01-11 |archive-url=https://web.archive.org/web/20220111180551/https://windowscmd.com/ |url-status=dead }} * [https://www.colorconsole.de/console/en/index.htm Most important CMD commands in Windows - colorconsole.de]
{{Microsoft Windows components}} {{Windows commands}}
Category:Command shells Category:OS/2 command shells Category:Windows command shells Category:OS/2 commands Category:OS/2 files Category:Windows commands Category:Windows files Category:Windows components