Lably
Skip to content

Cmd.exe

Shell for Windows NT and other operating systems

  • 5 min read
  • 3 chapters

Related on Lably

Through Computer program, Microsoft Windows and DOS

Older, related operating systems, DOS and Windows 9x, provided COMMAND.COM as the shell. cmd.exe replaced 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 cmd.exe.

The initial version of cmd.exe for Windows NT was developed by Therese Stowell. Windows CE 2.11 was the first embedded Windows release to support a console and a Windows CE version of cmd.exe. The ReactOS implementation of 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, 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 &, && or ||.

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

<span id="mweQ"></span><span class="gp" id="mweg">></span>CommandA <span class="p" id="mwew">&</span> CommandB <span class="p" id="mwfA">&</span> CommandC

With the && separator, a command must succeed, i.e. yield the exit code 0, 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.

<span id="mwhQ"></span><span class="gp" id="mwhg">></span>CommandA <span class="p" id="mwhw">&&</span> CommandB <span class="p" id="mwiA">&&</span> CommandC

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, CommandB executes if CommandA fails, and CommandC executes if CommandB succeeds.

<span id="mwkQ"></span><span class="gp" id="mwkg">></span>CommandA <span class="p" id="mwkw">||</span> CommandB <span class="p" id="mwlA">&&</span> 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 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:

<span id="mwrQ"></span><span class="gp" id="mwrg">></span><span class="k" id="mwrw">echo</span> me <span class="p" id="mwsA">&</span> you <span class="go" id="mwsQ">me</span> <span class="go" id="mwsg">'you' is not recognized as an internal or external command,</span> <span class="go" id="mwsw">operable program or batch file.</span> <span class="gp" id="mwtA">></span><span class="k" id="mwtQ">echo</span> <span class="s2" id="mwtg">"me & you"</span> <span class="go" id="mwtw">"me & you"</span>

Sign in to keep reading

2 more chapters are free with a Lably account.

More in Computing and communication