我正在创建一个批处理文件,其中有一个从到
/
的活跃变化的字符,为此,您显然需要清除屏幕,输出屏幕上已有的所有内容,然后在末尾添加下一个字符。
当我已经知道屏幕上的内容时,这并不难,但是我正在尝试使其成为一个可以随时被其他程序调用的程序。这就是为什么我需要一种收集屏幕上所有当前内容的方法,以便在调用我的程序时可以:
- 将屏幕上的所有内容收集到变量或临时文件中
- 清除屏幕并输出其内容 + char1
- 清除屏幕并输出其内容+ char2
- 重复2-3次指定次数
我可以管理 2-4 个,我只需要 1 的帮助。
有什么建议吗?这可能吗?
提前感谢莫娜。
这不是您的答案,但它显示了一个微调器,您可能没有看到该技术:
第二个演示紧随其后,但它可能无法在 Windows 8 .
@Echo OFF
SetLocal EnableExtensions EnableDelayedExpansion
For /f %%a in ('copy /Z "%~dpf0" nul') Do set "CR=%%a"
Set "busy=|/-"
Set /A n=0
::BUSY SPINNER
For /L %%i in (0,1,10) Do (
Set /A "n=%%i%%4"
For /L %%n in (!n! 1 !n!) Do Set /P "=Calculating !busy:~%%n,1! !CR!"<NUL:
PING -n 2 127.0.0.1 >NUL:
)
::COUNTDOWN
For /L %%i in (10,-1,1) Do (
Set /P "=Backup will begin in %%i seconds. !CR!"<NUL:
PING -n 2 127.0.0.1 >NUL:
)
::PROGRESS
For %%i in (*) Do (
Set /P "=Copying %%i !CR!"<NUL:
PING -n 2 127.0.0.1 >NUL:
)
Set /P "=Done. !CR!"<NUL:
pause
这是旋转旋转器的第二个演示:
@echo off
:jeb
setlocal EnableDelayedExpansion
if "%~1"==":::" goto :spinnerThread
:menuLoop
<nul set /p menu=Select menu[1 or 2]=
call :GetKey
echo(
echo Pressed '!key!'
if !key!==1 call :menu1
if !key!==2 call :menu2
if !key!==2 call :menu2
goto :menuLoop
:menu1
:menu2
call :spinnerStart
rem do some work
ping localhost -n 3 > nl
call :spinnerStop
echo Finished
exit /b
:spinnerStart
del spinnerStop.tmp > nul 2>&1
start /b "" cmd /c "%~df0" :::
exit /b
:spinnerStop
echo dummy > spinnerStop.tmp
:__spinnerStop
if exist spinnerStop.tmp goto :__spinnerStop
exit /b
:spinnerThread
for /f %%a in ('copy /Z "%~f0" nul') do set "CR=%%a"
set "spinChars=|/-"
:spinnerLoop
set /a "spinner=(spinner + 1) %% 4"
<nul set /p ".=Waiting...!spinChars:~%spinner%,1!!CR!"
ping localhost -n 2 > nul 2>&1
if not exist spinnerStop.tmp goto :spinnerLoop
del spinnerStop.tmp > nul 2>&1
echo(
exit /b
:GetKey
set "key="
for /F "usebackq delims=" %%L in (`xcopy /L /w "%~f0" "%~f0" 2^>NUL`) do (
if not defined key set "key=%%L"
)
set "key=%key:~-1%"
exit /b