Command Prompt

Also known as: cmd.exe · CMD

On this page 7

Command Prompt is the classic command-line interpreter of Windows, the program cmd.exe that reads typed commands or batch files, executes them and prints text output. In Windows administration it remains the most universally available shell, present in every edition since Windows NT and in recovery environments, even though PowerShell has become the preferred tool for automation.

Command Prompt is often called CMD or simply the console. Strictly speaking, cmd.exe is only the interpreter; the window that shows it is provided by a separate console host, today either the legacy conhost or Windows Terminal, which is the default terminal application in current Windows 11 releases.

How cmd.exe interprets commands

Command Prompt descends from COMMAND.COM of MS-DOS and keeps much of its syntax for compatibility, but it was rewritten as a 32-bit program for Windows NT in 1993. Each line passes through a parsing sequence: environment variables written as %NAME% are expanded, special characters such as pipes and redirections are processed, and the first word is resolved as either a built-in command or an executable.

Executables are located through the PATH variable and the extensions listed in PATHEXT, such as .COM, .EXE, .BAT and .CMD. Every command returns an exit code, stored in %ERRORLEVEL%, where 0 conventionally means success. A single command line is limited to 8,191 characters, a limit that long file lists or generated commands can reach.

TypeExamplesWhere it lives
Internal commandsdir, cd, copy, set, echo, for, ifBuilt into cmd.exe
External commandsipconfig, robocopy, diskpart, sfc, pingSeparate executables in System32
Batch scriptsFiles with .bat or .cmd extensionRun line by line by cmd.exe
Internal and external commands

Operators, redirection and variables

Much of the practical power of Command Prompt comes from a small set of operators that connect commands and route their output. They work in both interactive sessions and batch files.

OperatorMeaningExample
>Redirects output to a file, overwriting itdir > list.txt
>>Appends output to a fileecho done >> log.txt
2>&1Sends errors to the same place as outputbuild.cmd > out.txt 2>&1
|Pipes output into another commandtasklist | find "chrome"
&&Runs the next command only on successcd C:\src && dir
||Runs the next command only on failureping host || echo offline
^Escapes a special characterecho 5 ^> 3
Essential Command Prompt operators

Variables are plain text. Inside loops and blocks, standard expansion happens once per block, so batch files that update a variable inside a loop must enable delayed expansion with setlocal enabledelayedexpansion and read the value as !NAME!. Forgetting this is the most common source of puzzling batch file bugs.

Command Prompt compared with PowerShell

The fundamental difference is that Command Prompt passes text between commands, while PowerShell passes .NET objects with properties. This makes PowerShell far better for filtering, formatting and remote management, whereas cmd remains simpler for short tasks and legacy scripts.

AspectCommand PromptPowerShell
Data passed in pipesPlain textStructured objects
Scripting languageBatch syntax with goto and labelsFull language with functions and modules
Remote managementLimited, through separate toolsBuilt-in remoting
Error handlingExit codes onlyExceptions and try/catch
Startup timeNear instantSlightly slower
AvailabilityEvery Windows version and recovery modeWindows PowerShell 5.1 plus installable PowerShell 7
Command Prompt and PowerShell side by side

Most external tools such as ipconfig, robocopy or DISM work identically in both shells, because they are standalone programs. Differences appear in built-in syntax: dir /s in cmd corresponds to Get-ChildItem -Recurse in PowerShell.

Typical uses and elevated sessions

Command Prompt remains the tool of choice for quick diagnostics and for environments where nothing else is available, such as the Windows Recovery Environment. Many system maintenance commands also require an elevated prompt, opened with Run as administrator, because User Account Control otherwise runs the shell with standard rights.

  • Network diagnostics: ipconfig /all, ping, tracert, nslookup, netstat -ano.
  • System repair: sfc /scannow and DISM /Online /Cleanup-Image /RestoreHealth in an elevated session.
  • File operations: robocopy for reliable copying with retry and mirroring options.
  • Legacy automation: existing batch files for logon scripts and build steps.
  • Starting cmd itself: cmd /c runs one command and exits, cmd /k keeps the window open.

Built-in help is available for nearly every command by appending /?, and help lists the internal commands. Because Command Prompt cannot run PowerShell cmdlets directly, mixed scripts usually call powershell -NoProfile -Command for the parts that need objects, while keeping the surrounding batch logic in cmd. Settings such as the default terminal application and font are controlled by the console host, not by cmd.exe itself.

Common pitfalls in Command Prompt

Many errors in cmd come from its text-based parsing rules, which handle spaces and special characters differently from modern shells.

ProblemCauseFix
Path with spaces failsArguments split at spacesEnclose the path in double quotes
Access denied on system commandsShell is not elevatedOpen the prompt as administrator
Variable not updated in a loopExpansion happens before the loop runsUse delayed expansion
Garbled non-English charactersLegacy code pageSwitch code page with chcp 65001
Script continues after a failureExit codes not checkedTest %ERRORLEVEL% or use ||
Frequent problems and fixes

For new automation, the practical recommendation is to write PowerShell scripts and keep Command Prompt for short interactive tasks, existing batch files and recovery work.

In everyday language

Command Prompt is a window where you talk to Windows by typing instead of clicking. You type a short instruction, press Enter, and the computer answers with lines of text.

It is old and simple, a bit like a reliable manual screwdriver next to a modern power tool. PowerShell can do more, but Command Prompt is always there, starts instantly and is often the quickest way to check a network connection or run a repair command.

Seen in the real world

A help desk technician receives a call from an employee whose laptop cannot reach the company intranet. The technician asks the user to open Command Prompt and type ipconfig /all, which shows an address starting with 169.254, a sign that the laptop did not obtain an address from the DHCP server.

The technician has the user run ipconfig /release followed by ipconfig /renew, and then ping to the intranet server. The laptop receives a valid address and the ping succeeds. Later, an elevated session with sfc /scannow repairs two corrupted system files that had caused occasional network adapter errors.

The outcome is a problem solved in about ten minutes with built-in commands only, without remote access software or additional tools.