Any command to add margin or space between pause command and the window borders?
2 Answers
You can suppress the text from Pause
and place your own, before.
echo ..Press a key to continue..
pause > nul

- 78,592
- 17
- 171
- 225
It is possible with set /P
to output a text of your choice with leading and trailing spaces as wanted with waiting on same line for any key press using pause
.
Here is the code:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
set /P "MyDummyVar=* Please press a key to continue ... " <nul & pause >nul & echo(
endlocal
ATTENTION: The prompt text cannot start with leading normal spaces (code value decimal 32, hexadecimal 20), horizontal tabs (code value decimal 9, hex. 09) or non-breaking spaces according to current code page (code value 255, hex. FF for OEM code pages like 437 or 850, code value 160, hex. A0 for ANSI code pages like Windows-1252). The command SET removes all leading whitespaces before printing the prompt text.
The posted solution uses a prompt text starting with an asterisk and the second character is a backspace control character with decimal code value 8. There can be used also a different non-whitespace character than the asterisk as first character.
Note: The browser used to view this page might not display the backspace control character after *
at all, but the posted code has a backspace control character after *
. It depends on the used browser if the backspace control character is copied also with the three normal spaces and all the other characters of third command line. It depends on the used text editor how the backspace character is pasted into the batch file on really copied as backspace by the browser and on the used font how the backspace control character is displayed in the text editor window if displayed at all.
This solution is inspired by Windows batch: echo without new line written by dbenham and the DosTips forum post Output text without linefeed, even with leading space or = written by jeb.
& echo(
at end of the command line is necessary to have the next output on next line and not on same line as the prompt text because of the newline characters output by pause
are redirected also to device NUL.
Another solution for Windows Vista and newer Windows versions and Windows Server 2003 and newer Windows Server versions is:
%SystemRoot%\System32\choice.exe /N /M " Please press a key to continue ..." <nul 2>nul & pause >nul & echo(
Note: choice.exe
is by default not available on Windows XP. choice.exe
of Windows Server 2003 can be copied into the Windows system directory of Windows XP to make it available also on a computer running Windows XP. In other words this solution should not be used in batch files which should run also on Windows XP or Windows 2000.
There are used three non-breaking spaces in this example with OEM code value 255 (hexadecimal FF) at beginning of the prompt text which the command CHOICE does not remove in comparison to leading normal spaces and horizontal tabs which are removed by CHOICE.
CHOICE outputs the prompt text always with one trailing space appended after removing trailing normal spaces/horizontal tabs from prompt text. Trailing non-breaking spaces are not removed by CHOICE and can be appended at end of the prompt text for even more output trailing spaces.
The device NUL is used for the standard input stream which results in the error message:
ERROR: The file is either empty or does not contain the valid choices.
This error message is redirected with 2>nul
to device NUL to suppress it.
The result is that choice.exe
immediately terminates itself after printing the prompt text and so internal command pause
is executed next by cmd.exe
.
It would be best on using this solution to get the number of currently used code page as suggested by Compo in DosTips form post [Info] Saving current codepage, next set OEM code page 437 as used to encode the prompt text with the non-breaking spaces, output the prompt and restore the initial code page. This can be done with the following code:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
for /F "tokens=*" %%G in ('%SystemRoot%\System32\chcp.com') do for %%H in (%%G) do set "CodePage=%%~nH"
%SystemRoot%\System32\chcp.com 437 >nul
%SystemRoot%\System32\choice.exe /N /M " Please press a key to continue ..." <nul 2>nul & pause >nul & echo(
%SystemRoot%\System32\chcp.com %CodePage% >nul
endlocal
PS: I have never understood why command PAUSE does not support optionally an argument string which is interpreted as prompt text instead of the built-in prompt text. I wrote in year 2002 a very small 32-bit console application as replacement for pause
which I called batpause.exe
which is like PAUSE and supports optionally an argument string interpreted as prompt text output by the small application instead of built-in default prompt text.

- 46,139
- 17
- 80
- 143