我有一个带有一些标签的蝙蝠,所以我开始我的 bat 检查是否传递了任何参数,如果没有,执行将通过一个参数对 bat 本身进行新调用,一旦完成,它将继续执行下一个命令。
当 bat 通过一个带参数的调用开始时,它的执行将在 :label 内循环(永久)
这是一个可能需要很长时间才能运行的蝙蝠,因此调用会导致“无限”进度条出现在窗口标题中,并在后台循环执行。
因为在屏幕上或标题栏中看到静态行(“Finding Nemo, Files, etc...”)很乏味,而且最近一个需要很长时间的任务/脚本示例正在寻找更新的通过扫描所有驱动程序并比较结果以获得一个(更新的)可执行文件(版本/日期),在此处回答。
以上面链接的代码为一个耗时的任务示例,并在标题中添加一个进度条,我有以下代码:
@echo off
if "%~1."=="." (call start ".:." /b cmd.exe /v:on /c "%~f0" ? )else goto %:^|
setlocal enabledelayedexpansion && set "_f=" && set "_ff=" && set /a "_cnt=0"
for /f usebackq^tokens^=* %%f in (`%__AppDir__%mountvol.exe^|find.exe /i ":\"
`)do 2>nul pushd %%~f && (set/a "_cnt+=1" && call %:^) _ff_!_cnt! & popd)
for /f useback^tokens^=1*delims^=^=^ %%i in (`^<nul ^<con: set _ff_ ^|%__AppDir__%sort.exe /r
`)do <con: <nul call set "_ffprobe=%%~dpnxj" & call set "_ffprob_Path=%%~dpj" & goto %:^V
%:^)
for /f usebackq^tokens^=2^,4* %%i in =;(`2^>nul %__AppDir__%where.exe /r \ ffprobe.exe /t ^|^
%__AppDir__%sort.exe /r^|^|exit/b`)do set "_f=%%~k" && for /f useback^delims^=. %%G in (`
^<con %__AppDir__%wbem\wmic.exe DataFile where name^="!_f:\=\\!" get LastModified ^|^
%__AppDir__%findstr.exe /rb [0-9]`)do <con: <nul call set "%~1=%%~k" && exit /b 0
%:^|
>nul chcp 65001 & mode 89,5 & set "_title=Looking for your latest ffprob.exe, please wait^!!"
<con: ;color 0a && set^ "_176=░░░░░░░░░░" && set^ "_255=▓▓▓▓▓▓▓▓▓▓" && set^ "_022=▬▬▬▬▬▬▬▬▬▬"
call setlocal enabledelayedexpansion & set "_ping=%__AppDir__%pathping.exe 127.1 -q 1 -p 050"
%:^/
set "_title=I'm doing something that takes a while, please wait^!!"
for %%G in =;(1,2,3,4,5,6,0)do if "!_ffprob_Path!\." == "\." =;( if ".\%%~G\." == ".\1\." =;(
for /l %%L in (0 01 10)do %_ping% |title !_title! [!_255:~0,%%~L!!_022:~%%L!] !time:~,8!
)else if "%%G\" == "2\" =;(if "!_ffprob_Path!\." == "\." =;(
for /l %%L in (10 -1 0)do %_ping% |title !_title! [!_255:~0,%%~L!!_176:~%%L!] !time:~,8!
))else if "%%G\" == "3\" =;(if "!_ffprob_Path!\." == "\." =;(
for /l %%L in (0 01 10)do %_ping% |title !_title! [!_022:~0,%%~L!!_176:~%%L!] !time:~,8!
))else if "%%G\" == "4\" =;(if "!_ffprob_Path!\." == "\." =;(
for /l %%L in (10 -1 0)do %_ping% |title !_title! [!_022:~0,%%~L!!_255:~%%L!] !time:~,8!
))else if "%%G\" == "5\" =;(if "!_ffprob_Path!\." == "\." =;(
for /l %%L in (0 01 10)do %_ping% |title !_title! [!_176:~0,%%~L!!_255:~%%L!] !time:~,8!
))else if "%%G\" == "6\" =;(if "!_ffprob_Path!\." == "\." =;(
for /l %%L in (10 -1 1)do %_ping% |title !_title! [!_176:~0,%%~L!!_022:~%%L!] !time:~,8!
))else if "%%G\" == "0\" =;(if "!_ffprob_Path!\." == "\." =;(
goto %:^/
)));=
%:^V
rem./ your code continues at this point using: / & echo+!_ffprob_Path! & echo+!_ffprobe!
结果是“无限”进度条开始并且不会停止,即使在设置变量之后,它应该在进度条标签中表示循环结束,但它不起作用......
使用启用/禁用 setlocal 进行了几次尝试,颠倒了标签调用的顺序,以及我什至不记得的事情,但是有几次尝试结束循环但没有成功......
如何结束在同一蝙蝠后台运行的标签的循环?
我已经在这一点上很久了,我什么也没看到。
任何想法?
常规布局中的相同代码...
@echo off
if "%~1." == "." (
call start ".:." /b cmd.exe /v:on /c "%~f0" ?
) else (
goto %:^p
)
setlocal enabledelayedexpansion
set "_f="
set "_ff="
set /a "_cnt=0"
for /f "usebackq tokens=*" %%f in (`%__AppDir__%mountvol.exe ^| %__AppDir__%find.exe /i ":\"`) do 2>nul (
pushd %%~f && (
set /a "_cnt+=1"
call %:^) _ff_!_cnt!
popd
)
)
for /f "usebackq tokens=1* delims==" %%i in (`set _ff_ ^| %__AppDir__%sort.exe /r`) do (
call set "_ffprobe=%%~dpnxj"
call set "_ffprob_Path=%%~dpj"
goto %:^V
)
%:^)
for /f "usebackq tokens=2,4*" %%i in (`2^>nul %__AppDir__%where.exe /r \ ffprobe.exe /t ^| %__AppDir__%sort.exe /r ^|^| exit /b`) do (
set "_f=%%~k"
for /f "usebackq delims=." %%G in (`^<con: call %__AppDir__%wbem\wmic.exe DataFile where name^="!_f:\=\\!" get LastModified ^| %__AppDir__%findstr.exe /rb [0-9]`)do (
call set "%~1=%%~k"
exit /b 0
)
)
%:^p
>nul chcp 65001
%__AppDir__%mode.com con: cols=89 lines=5
set "_title=Looking for your latest ffprob.exe, please wait^!!"
color 0a
set "_176=░░░░░░░░░░"
set "_255=▓▓▓▓▓▓▓▓▓▓"
set "_022=▬▬▬▬▬▬▬▬▬▬"
setlocal enabledelayedexpansion
set "_ping=%__AppDir__%pathping.exe 127.1 -q 1 -p 050"
%:^/
for %%G in =;(1,2,3,4,5,6,0)do (
if "!_ffprob_Path!\." == "\." (
if ".\%%~G\." == ".\1\." (
for /l %%L in (0 01 10) do %_ping% | title !_title! [!_255:~0,%%~L!!_022:~%%L!] !time:~,8!
)else if "%%G\" == "2\" (
if "!_ffprob_Path!\." == "\." (
for /l %%L in (10 -1 0) do %_ping% | title !_title! [!_255:~0,%%~L!!_176:~%%L!] !time:~,8!
)
)else if "%%G\" == "3\" (
if "!_ffprob_Path!\." == "\." (
for /l %%L in (0 01 10) do %_ping% | title !_title! [!_022:~0,%%~L!!_176:~%%L!] !time:~,8!
)
)else if "%%G\" == "4\" (
if "!_ffprob_Path!\." == "\." (
for /l %%L in (10 -1 0) do %_ping% | title !_title! [!_022:~0,%%~L!!_255:~%%L!] !time:~,8!
)
)else if "%%G\" == "5\" (
if "!_ffprob_Path!\." == "\." (
for /l %%L in (0 01 10) do %_ping% | title !_title! [!_176:~0,%%~L!!_255:~%%L!] !time:~,8!
)
)else if "%%G\" == "6\" (
if "!_ffprob_Path!\." == "\." (
for /l %%L in (10 -1 1) do %_ping% | title !_title! [!_176:~0,%%~L!!_022:~%%L!] !time:~,8!
)
)else if "%%G\" == "0\" (
if "!_ffprob_Path!\." == "\." (
goto %:^/
)
)
)
)
%:^V
rem./ your code continues at this point using: /
echo+!_ffprob_Path!
echo+!_ffprobe!