[ About | Licence | Contacts ]
Written by Oleksandr Gavenko (AKA gavenkoa), compiled on 2024-04-01 from rev 052223c22317.

CMD Windows shell.

Defining prompt

Set the environmet variable PROMPT, example of .reg file:

"PROMPT"="cmd# "

I embedded current time and directory; also a new line for readability of commands when a current working directory path is too long:


CMD has built-in command to modify this env var:

prompt "FORMAT"

To list available options use prompt /?.

Resize a conhost window

cmd# mode CON: COLS=120 LINES=40


Parsing C Command-Line Arguments


Variable name start with letter and underscore, next chars can be letter, number and underscore. Variable name is case insensitive.

List variables:

cmd# set

Use syntax %NAME% to expand NAME value.

Use set command to define environment variable (/p is with a user input, /a for arithmetic expressions):

set /p PASS="Enter password: "
set /a NUM="1+2"

To delete env variable set it to empty value:

set VAR=

To load first line from a file into a variable:

cmd> set /p VAR=<FILE

CMD tricks

$ set /p TOOLOUTPUT= < temp.txt

$ for /f "tokens=*" %%i in ('%~dp0sometool.exe') do set TOOLOUTPUT=%%i

$ for /f "tokens=1 delims=" %%s in (users.txt) do (echo %%S & command "%%S") >> outputfile.txt


Variable value and one line command string after expansion can not exceed 8191 characters for Windows XP and later and 2047 for Windows NT, Windows 2000.

Command prompt (Cmd. exe) command-line string limitation.

How run cmd on 64-bit OS.

From 64-bit process:

%windir%\System32\cmd.exe (for 64-bit)
%windir%\SysWOW64\cmd.exe (for 32-bit)

From 32-bit process:

%windir%\System32\cmd.exe (for 32-bit)
%windir%\Sysnative\cmd.exe (for 64-bit)
File System Redirector