cmd.exe
{{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 (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
}}
cmd.exe, a.k.a. Command Prompt, is a shell program on later versions of Windows (NT and CE families), OS/2,{{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}}, eComStation, ArcaOS, and ReactOS. In some versions of Windows (CE .NET 4.2,{{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}} CE 5.0{{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}} and Embedded CE 6.0{{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}}) 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.{{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}} Windows CE 2.11 was the first embedded Windows release to support a console and a Windows CE version of {{mono|cmd.exe}}.{{Cite book|author=Douglas McConnaughey Boling|year=2001|title=Programming Microsoft Windows CE|edition=2nd|publisher=Microsoft Press|isbn=978-0735614437}} The ReactOS implementation of {{mono|cmd.exe}} is derived from FreeCOM, the FreeDOS command line interpreter.
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 separator {{code|&}} or {{code|&&}}.{{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}}
With the {{code|&}} separator, a subsequent command is executed even if the previous command indicates an error.{{Cite web|title=Command Redirection, Pipes - Windows CMD - SS64.com|url=https://ss64.com/nt/syntax-redirection.html|access-date=2021-09-23|website=ss64.com}} 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 {{code|&&}} separator, a command must complete successfully 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.
>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 expansions[https://support.microsoft.com/en-us/help/830473/command-prompt-cmd-exe-command-line-string-limitation Command prompt (Cmd.exe) command-line string limitation] 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: &<>[]{}^=;!'+,`~
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:
me
'you' is not recognized as an internal or external command,
operable program or batch file.
>echo "me & you"
"me & you"
Internal commands
=OS/2=
File:Microsoft OS 2 Version 1.3 cmd.exe OS 2 Window 640x373.png
Internal commands in OS/2:{{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}}
{{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]]
Internal commands in Windows NT and later:{{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}}
{{Div col|colwidth=6em}}
- assoc
- break
- call
- cd
- chdir
- cls
- color
- copy
- date
- del
- dir
- dpath
- echo
- endlocal
- erase
- exit
- for
- ftype
- goto
- help
- 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]]
Internal commands in Windows CE .NET 4.2,{{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}} Windows CE 5.0{{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}} and Windows Embedded CE 6.0:{{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}}
{{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=
File:ReactOS-0.4.13 cmd.exe Command Prompt 667x434.png
Internal commands in ReactOS:{{Cite web|url=https://github.com/reactos/reactos |title=reactos/reactos |website=GitHub |date=December 4, 2021}}
{{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 enhancments 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
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 {{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. The extensions can be disabled, providing a stricter compatibility mode.
- The {{mono|COMMAND.COM}}
DELTREE
command was merged into therd
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.
- 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
for
command supports parsing files and arbitrary sets in addition to file names. - The new
pushd
andpopd
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
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}}