Home > Commands A-M > Commands Ch-Cz

CMD


Description | Syntax | Parameters | Switches | Related | Notes | Examples | Errorlevels | Availability

Starts a new instance of the NT command interpreter.

A command interpreter is a program that lets you type commands. Use the EXIT command to stop the new command interpreter and return control to the old one.


Syntax

CMD /?

CMD [/A | /U] [/D] [/F:ON | /F:OFF] [/Q] [/T:fg] [/V:ON | /V:OFF] [[/X | /E:ON] | [/E:OFF | /Y]] [[/S] [/C command] | [/K command]]


Parameters

none.


Switches
/? (NTXP)
Display help.
/A (NT3.5)
Output ANSI Characters.
/C command (NT3.5)
Specifies that the command interpreter is to perform the specified command and then exit. This switch must be the last switch on the command-line.
/R same as /C.
/D (NT2000)
Ignore registry AUTORUN commands (HKLM | HKCU \Software\Microsoft\Command Processor\AutoRun).
/F: [ON | OFF] (NT2000)
Enable/disable auto-completion of pathnames entered at the CMD prompt. /F:OFF is the default.
At the command prompt CTRL-D (^D) gives folder name completion and CTRL-F (^F) gives file and folder name completion.
These CTRL keys build up a list of paths that match and display the first matching path. Thereafter, repeated pressing of the same control key will cycle through the list of matching paths. Pressing SHIFT with the control KEY will move through the list backwards.
/K command (NT3.5)
Runs the specified command, program, or batch program and then displays the NT command prompt. This switch must be the last switch on the command-line.
/Q (NT3.5)
Turns echo off.
/S (NT2000)
Strips quotes from command string.
/T:fg (NT4)
Sets the foreground/background colours. See COLOR for a list of colour codes.
/U (NT4)
Output UNICODE Characters.
/V: [ON | OFF] (NT2000)
Enable/disable delayed environment variable expansion. (This allows a FOR loop to specify !variable! instead of %variable% expanding the variable at execution time instead of at input time).
Environment expansion preference can be set permanently in the registry HKLM | HKCU \Software\Microsoft\Command Processor\DelayedExpansion Set to either 0x1 or 0x0
/X (NT4 ONLY)
/Y (NT4 ONLY)
/E: [ON | OFF] (NT2000)
Enable/disable extensions to CMD.EXE.
/X same as /E:ON.
/Y same as /E:OFF.
Command Extensions are enabled by default unless you are running a 16-bit script (command.com or a .BAT file) in which case they are not available at all.
Command extensions are controlled by setting a value in the registry (HKCU \Software\Microsoft\Command Processor\EnableExtensions) 0 = disable extensions, 1 = enable extensions

Related

EXIT - Use this to close a CMD shell and return.
CALL - Call one batch program from another
START - Start a separate window to run a specified program or command
DOSKEY Edit command-line, recall commands
Equivalent Linux BASH commands:
builtin - Run a shell builtin
bash - run the bash shell
chroot - Run a command with a different root directory
csh - run the C shell
exec - Execute a command
ksh - run the Korn shell
sh - run the Bourne shell


Notes

CMD.exe is the NT equivalent of Command.com in previous operating systems. The older 16-bit command processor command.com is supplied to provide backward compatibility for 16-bit DOS applications.

To ensure that an NT batch file will not run if accidentally copied to a Windows 95/98/ME machine you should use the extension .CMD rather than .BAT.

The %COMSPEC% environment variable will show if you are running CMD.EXE or command.com.

It is possible to run the Windows 2000 CMD.EXE under NT 4.0.

The environment Variable %CMDCMDLINE% will expand into the original command-line passed to CMD.EXE.

Under Windows NT, the command-line is limited to 256 characters. The command processor was patched from NT 4 Service Pack 4 to prevent this limitation from causing a stack overflow.

Multiple commands separated by the command separator '&&' are accepted if surrounded by quotes.

This logic is used to process quote (") characters:

  1. If all of the conditions are met, then quote characters on the command-line are preserved:
  2. Otherwise, old behavior is to see if the first character is a quote character and if so, strip the leading character and remove the last quote character on the command-line, preserving any text after the last quote character.

The key combination ALT-ENTER will switch a CMD window to full-screen mode. Press ALT-ENTER again to return to a normal Window.


Examples

none.


Errorlevels

none.


Availability
External
DOS
none
Windows
none
Windows NT
NT3.5 NT4 NT2000 NTXP NT2003