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.
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]]
none.
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
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:
The key combination ALT-ENTER will switch a CMD window to full-screen mode. Press ALT-ENTER again to return to a normal Window.
Missing the /Y option of COMMAND.COM to step through (debug) a batch file line by line? Here is a replacement:
@ECHO OFF
:: 2004Jan31 Rick Lively - Create
:: 2004Feb03 Rick Lively - Add COMSPEC option
:: 2005Mar23 Steve Rogan - Rework for long file names, to handle directory changes,
:: delay envvar expansion, and handle multi-line source commands.
:: 2005Apr14 Steve Rogan - Fix a long file name problem, allow multiple invocations
:: using unique temp debug file names.
:: Check for correct syntax.
IF "%~1" == "" GOTO :rlCmd30
:: Check if we're already running.
IF EXIST %TEMP%\"dbg_%~n1.bat" GOTO :rlCmd10
:: Hide some process variables and enable special env var processing.
SETLOCAL ENABLEDELAYEDEXPANSION
SET rlDbgFile="dbg_%~n1.bat"
:: Check for possible extensions, and build a sub-batch file.
IF EXIST "%~1.bat" (
:: CALL %0 "%~1.bat"
SET rlFileName=%~pn1.bat
GOTO :BuildFile
)
IF EXIST "%~1.cmd" (
:: CALL %0 "%~1.cmd"
SET rlFileName=%~pn1.cmd
GOTO :BuildFile
)
IF EXIST "%~1" (
:: CALL %0 "%~1.cmd"
SET rlFileName=%~pnx1
GOTO :BuildFile
)
GOTO :rlCmd20
:BuildFile
:: Create a sub-batch file that calls us back after each line where we have the opportunity to "rem"
:: out the next executable line, execute it, or goto the end. Don't export remarks and blank lines.
SET rlLineOpen=0
SET rlCmd=
ECHO @ECHO OFF>%TEMP%\%rlDbgFile%
FOR /F "tokens=* usebackq" %%F IN ("%rlFileName%") DO (
SET rlCmdLine=%%F
SET rlCmdLine=!rlCmdLine:"='!
IF /I "!rlCmdLine:~0,4!" NEQ "REM " IF /I "!rlCmdLine:~0,2!" NEQ "::" IF /I "!rlCmdLine!" NEQ "" (
CALL :ExportPrefix %0 "%~n1.bat"
ECHO %%F>>%TEMP%\%rlDbgFile%
CALL :ExportSuffix
)
)
ENDLOCAL
:: Invoke our sub-batch file, then clean up afterwards.
CMD /C %TEMP%\"dbg_%~n1.bat" %2 %3 %4 %5 %6 %7 %8 %9
ERASE "%TEMP%\dbg_%~n1.bat"
GOTO :rlCmd40
:ExportPrefix
:: Check if this is a line continuation. If not, output the prefix.
IF "%rlLineOpen%" LSS "1" (
ECHO CALL %1 %2 "%rlCmdLine%">>%TEMP%\%rlDbgFile%
ECHO %%rlCmd%% GOTO :rlCmdNext>>%TEMP%\%rlDbgFile%
)
GOTO :EOF
:ExportSuffix
:: Check if this is the end of the continuation. If so, clear the "open" flag.
SET rlCmdLine="%rlCmdLine: =%"
IF "%rlCmdLine:~1,1%" == ")" SET /A rlLineOpen=%rlLineOpen%-1
:: Check if this line is continued. If so, set the "open" flag.
IF "%rlCmdLine:~-2,1%" == "(" SET /A rlLineOpen=%rlLineOpen%+1
:: Check if the line is "open". If not, output the suffix.
IF "%rlLineOpen%" LSS "1" ECHO :rlCmdNext>>%TEMP%\%rlDbgFile%
GOTO :EOF
:rlCmd10
:: This routine is called between every executable line in our sub-batch to give
:: us the chance to control execution of the next line.
SET rlCmd=y
SET /P rlCmd=(%time%)-^>"%~2" [Yncq]?
IF /I "%rlCmd%" EQU "c" (
%COMSPEC% /K PROMPT=$T $P$_rlCmdY$G
GOTO :rlCmd10
)
IF /I "%rlCmd%" NEQ "Y" IF /I "%rlCmd%" NEQ "q" IF /I "%rlCmd%" NEQ "n" GOTO :rlCmd10
IF /I "%rlCmd%" EQU "n" SET rlCmd=
IF /I "%rlCmd%" EQU "Y" SET rlCmd=::
IF /I "%rlCmd%" EQU "q" SET rlCmd=GOTO :EOF
GOTO :EOF
:rlCmd20
ECHO.
ECHO file '%1' '%1.bat' '%1.cmd' NOT found
:rlCmd30
ECHO.
ECHO To step through (2K or XP) NT batch file: Test
ECHO prompts: [Yncq] Yes, No, Comspec, Quit
ECHO.
ECHO %0 Test
ECHO OR %0 Test.bat
ECHO OR %0 Test.cmd
ERASE "%TEMP%\dbg_*.bat">NUL
:rlCmd40
SET rlCmd=
SET rlCmdLine=
SET rlFileName=
SET rlDbgFIle=
SET rlLineOpen=
GOTO :EOF
none.