windows echo覆盖以前的echo

时间:2017-07-28 19:56:32

标签: windows batch-file cmd

在批处理文件中,我想写一个"计数器"到屏幕而不滚动屏幕上的东西。我有

FOR /L %%i IN (1,1,1000) DO (
< NUL set /P="Count= %%i"
)

< LT> NUL之间没有空格,但这会阻止该行显示。}

此命令不会添加LF或CR,但我确实需要CR,而不是LF。

最终结果应为

Count= X

其中X是&#34;计数&#34;从1到1,000。

2 个答案:

答案 0 :(得分:3)

@echo off
setlocal EnableDelayedExpansion

rem Get a Carriage Return (Ascii 13) in CR variable:
for /F %%a in ('copy /Z "%~F0" NUL') do set "CR=%%a"

FOR /L %%i IN (1,1,1000) DO ( < NUL set /P "=Count= %%i!CR!" )

答案 1 :(得分:0)

@echo off
setlocal EnableDelayedExpansion
set cnt=0
for /F %%a in ('copy /Z "%~F0" NUL') do set "CR=%%a"


FOR /L %%a IN (1,1,5) DO ( 
 call :cnt
 timeout /t 1 >nul
 < NUL set /P "=!er!!CR!"
 )
echo.
pause
exit 
:cnt
set /a cnt=!cnt!+1
if %cnt% == 1 set er=Hello!                             
if %cnt% == 2 set er=I am Soubhik Biswas                                 
if %cnt% == 3 set er=My Roll Is 40                          
if %cnt% == 4 set er=Is Study In Class VIII-C       
goto :eof