When we use the pause
it shows "Press any key to continue . . .". After pressing any key, the latter text remains, and the remaining text appears below it. If I use cls
after pause
the whole screen gets cleared.
Is there any method to remove only "Press any key to continue . . ." after pressing any key? Also, how do I clear only selected lines instead of clearing the whole screen?
It is not possible in
cmd
to delete certain lines. However, I can provide a work-around:There are multipe solutions for this problem, but batch doesn't offer a simple one.
The main problem of batch is, that you can't move the cursor up with normal commands.
1) You can use
cls
to clear the screen and redraw all necessary data again.2) You can use an external program to move the cursor (this programs can be created on the fly), like Move Cursor to 0,0
3) You can abuse the
timeout
command to go back to the second line Move cursor to screen home with TIMEOUT command!, a very cool trick discovered by Aacini4) With Windows 10 you can use Ansi-Escape sequences to move the cursor and get many other effects, but it will work only for Win10
You may also use a strange trick that combines a TAB character plus several BS ones to move the cursor up any number of lines:
IMPORTANT: You must be sure that the line
set "TAB= "
effectively contains a TAB (Ascii 9) character, not just spaces.Output before the PAUSE:
... and after the PAUSE:
Tested on Windows 8.1
This method was discovered by DosTips user neorobin and is fully described at this topic.