2 回答
You can ommit the CLS and recreating the full screen with the help of set /p
, as set /p
doesn't output a newline, you can append text.
Normally set /p
is for assigning text to a variable inputted by a user, but if you use redirection from NUL it simply outputs text.
@echo off
for /L %%n in (1 1 5 ) do (
<nul set /p ".=[]"
ping -n 2 localhost > nul
)
echo(
echo The end
The status update you asked for, can be handled the same way, as it only appends something to the line.
If you want to change parts of the line or the complete line, you need to move the cursor back or to the beginning of the line.
Both can be done with the backspace character or the carriage return character.
This is a sample which counts on a fixed screen location
setlocal EnableDelayedExpansion
for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"
for /L %%n in (1 1 1000) do (
<nul set /p ".=%%n!CR!"
)