Jump to content

Command Prompt (Windows)

From Wikipedia, the free encyclopedia

Template:Short description Template:Distinguish {{#invoke:other uses|otheruses}} Template:Use mdy dates

Template:Infobox software

Command Prompt, or Windows Command Processor, is a shell program on later versions of Windows (NT and CE families), OS/2,[1] eComStation, ArcaOS, and ReactOS.[2] In some versions of Windows (CE .NET 4.2,[3] CE 5.0[4] and Embedded CE 6.0[5]) 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 Template:Mono as the shell. Command Prompt (Template:Mono) replaced Template:Mono 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 Command Prompt.

The initial version of Command Prompt for Windows NT was developed by Therese Stowell.[6] Windows CE 2.11 was the first embedded Windows release to support a console and a Windows CE version of Command Prompt.[7] The ReactOS implementation of Command Prompt is derived from FreeCOM, the FreeDOS command line interpreter.[2]

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, Template:Mono 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 <syntaxhighlight lang="text" class="" style="" inline="1">&</syntaxhighlight>, <syntaxhighlight lang="text" class="" style="" inline="1">&&</syntaxhighlight> or ||.[8]

With the <syntaxhighlight lang="text" class="" style="" inline="1">&</syntaxhighlight> separator, a subsequent command is executed even if the previous command indicates an error.[9] 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 <syntaxhighlight lang="text" class="" style="" inline="1">&&</syntaxhighlight> separator, a command must succeed, i.e. yield the exit code 0, for the subsequent command to execute. In the following example, <syntaxhighlight lang="text" class="" style="" inline="1">CommandB</syntaxhighlight> only executes if <syntaxhighlight lang="text" class="" style="" inline="1">CommandA</syntaxhighlight> completes successfully, and <syntaxhighlight lang="text" class="" style="" inline="1">CommandC</syntaxhighlight> only executes if <syntaxhighlight lang="text" class="" style="" inline="1">CommandB</syntaxhighlight> also completes successfully.

<syntaxhighlight lang="doscon"> >CommandA && CommandB && CommandC </syntaxhighlight>

With the || separator, a command must fail, i.e. yield an exit code not equal 0, for the subsequent command to execute. In the following example, <syntaxhighlight lang="text" class="" style="" inline="1">CommandB</syntaxhighlight> executes if <syntaxhighlight lang="text" class="" style="" inline="1">CommandA</syntaxhighlight> fails, and <syntaxhighlight lang="text" class="" style="" inline="1">CommandC</syntaxhighlight> executes if <syntaxhighlight lang="text" class="" style="" inline="1">CommandB</syntaxhighlight> 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[10] 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:[8] &<>[]{}^=;!'+,`~ 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

File:Microsoft OS 2 Version 1.3 cmd.exe OS 2 Window 640x373.png
Template:Mono running in OS/2 Window on OS/2 version 1.3

Internal commands in OS/2:[11]

Template:Div col

Template:Div col end

Windows NT family

File:Windows11Terminal uk.png
Template:Mono running in Windows Terminal on Ukrainian Windows 11

Internal commands in Windows NT and later:[12]

Template:Div col

Template:Div col end

Windows CE

File:Microsoft Windows CE Version 3.0 (Build 126) cmd.exe Command Prompt 800x574.png
Pocket CMD v 3.0 (cmd.exe) on Windows CE 3.0

Internal commands in Windows CE .NET 4.2,[13] Windows CE 5.0[14] and Windows Embedded CE 6.0:[15]

Template:Div col

  • 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

Template:Div col end

The Template:Mono command is available as an external command.

ReactOS

File:ReactOS-0.4.13 cmd.exe Command Prompt 667x434.png
Template:Mono on ReactOS

Internal commands in ReactOS:[2]

Template:Div col

  • ?
  • alias
  • assoc
  • beep
  • call
  • cd
  • chdir
  • choice
  • cls
  • color
  • copy
  • ctty
  • date
  • del
  • delete
  • delay
  • dir
  • dirs
  • echo
  • echos
  • Template:Not a typo
  • Template:Not a typo
  • 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

Template:Div col end

Comparison with COMMAND.COM

On Windows, Template:Mono provides various user experience enhancements as compared to Template:Mono, including:

  • More detailed error reporting for malformed commands than the generic Template:Mono "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 Template:Mono, this functionality was only available in DR DOS (via HISTORY) and later via an external component called Template:Mono.
  • Adds rotating command-line completion for file and folder paths, where the user can cycle through results for the prefix using the Template:Keypress, and Template:Keypress for reverse direction.
  • Treats the caret character (Template:Mono) as the escape character; the character following it is to be taken literally. There are special characters in Template:Mono and Template:Mono 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 <syntaxhighlight lang="text" class="" style="" inline="1">SETLOCAL EnableDelayedExpansion</syntaxhighlight>, 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.[16] The extensions can be disabled, providing a stricter compatibility mode.
  • The Template:Mono DELTREE command was merged into the rd command via the <syntaxhighlight lang="text" class="" style="" inline="1">/S</syntaxhighlight> switch.
  • <syntaxhighlight lang="text" class="" style="" inline="1">SetLocal</syntaxhighlight> and <syntaxhighlight lang="text" class="" style="" inline="1">EndLocal</syntaxhighlight> commands limit the scope of changes to the environment. Changes made to the command line environment after <syntaxhighlight lang="text" class="" style="" inline="1">SetLocal</syntaxhighlight> are local to the batch file. <syntaxhighlight lang="text" class="" style="" inline="1">EndLocal</syntaxhighlight> restores the previous settings.[17]
  • The <syntaxhighlight lang="text" class="" style="" inline="1">call</syntaxhighlight> command allows subroutines within batch file. The Template:Mono <syntaxhighlight lang="text" class="" style="" inline="1">CALL</syntaxhighlight> command only supports calling external batch files.
  • File name parser extensions to the <syntaxhighlight lang="text" class="" style="" inline="1">set</syntaxhighlight> command are comparable with C shell.Template:Explain
  • The <syntaxhighlight lang="text" class="" style="" inline="1">set</syntaxhighlight> 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 <syntaxhighlight lang="text" class="" style="" inline="1">if</syntaxhighlight> 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

References

Template:Reflist

Further reading

Template:Commons category Template:Sister project

  • {{#invoke:citation/CS1|citation

|CitationClass=web }}

  • {{#invoke:citation/CS1|citation

|CitationClass=web }}

  • {{#invoke:citation/CS1|citation

|CitationClass=web }}

  • {{#invoke:citation/CS1|citation

|CitationClass=web }}

  • {{#invoke:citation/CS1|citation

|CitationClass=web }}

Template:Microsoft Windows components Template:Windows commands

  1. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  2. ↑ 2.0 2.1 2.2 {{#invoke:citation/CS1|citation |CitationClass=web }}
  3. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  4. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  5. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  6. ↑ Template:Cite book
  7. ↑ Template:Cite book
  8. ↑ 8.0 8.1 {{#invoke:citation/CS1|citation |CitationClass=web }}
  9. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  10. ↑ Command prompt (Cmd.exe) command-line string limitation
  11. ↑ Template:Cite book
  12. ↑ Template:Cite book
  13. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  14. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  15. ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
  16. ↑ Cite error: Invalid <ref> tag; no text was provided for refs named Delay
  17. ↑ Cite error: Invalid <ref> tag; no text was provided for refs named SetLocal