当我在 FOR 循环中执行程序时,我编写了自己的代码来尝试计算延迟。缺点是值 %time% 是在同一时刻评估的。所以我想问你,是否可以更改代码以将 2 个计算块(使用 SET /A)移动到单独的子例程中。我用 goto 在网上搜索了这个解决方案,但我不清楚如何返回循环。作为我发现的例子,在文件末尾提到。
@echo off
Setlocal EnableDelayedExpansion
FOR /F "tokens=*" %%A IN ('DATE/T') DO FOR %%B IN (%%A) DO SET Today=%%B
ECHO It's %Today% today
CHCP 1250 > NUL
SET tpath=TEMP
for /f "delims=" %%x in (delimiter.ini) do set TAB=%%x
if not exist proxies.ini (
echo Proxies not Found!
pause
exit
)
REM Set array of proxies
FOR /F "eol= tokens=1,2 delims=%TAB%" %%A IN (proxies.ini) DO (
if "%%A"=="*" (
SET asterisk=1
SET http_proxy=%%B
SET t0=%time%
wget.exe http://www.nasa.gov/images/content/297522main_image_1244_946-710.jpg
SET t1=%time%
REM FOR /F %%A IN ('TIME/T') DO SET t1=%%A
echo !t0!
SET /a s = !t0:~6,2!*100
SET /a c = !t0:~9,2!
SET /a c = "!c!-(!c!/10)*4"
SET /a d1 = !s!+!c!
echo !s!+!c! = !d1!
echo !d1!
echo !t1!
SET /a s = !t1:~6,2!*100
SET /a c = !t1:~9,2!
SET /a c = "!c!-(!c!/10)*4"
SET /a d2 = !s!+!c!
echo !s!+!c! = !d2!
SET /a delay = !d1!-!d2!
echo Delay:!delay!
pause
Echo Working proxy ... !proxy!
)
)
pause
编辑 这是第二次测试,在 dBenham 发布他更好的解决方案之前:
@echo off
Setlocal EnableDelayedExpansion
FOR /F "tokens=*" %%A IN ('DATE/T') DO FOR %%B IN (%%A) DO SET Today=%%B
ECHO It's %Today% today
CHCP 1250 > NUL
SET tpath=TEMP
for /f "delims=" %%x in (delimiter.ini) do set TAB=%%x
if not exist proxies.ini (
echo Proxies not found.
pause
exit
)
REM Set array of proxies
FOR /F "eol= tokens=1,2 delims=%TAB%" %%A IN (proxies.ini) DO (
if "%%A"=="*" (
SET asterisk=1
SET http_proxy=%%B
SET t0=!time!
wget.exe http://www.nasa.gov/images/content/297522main_image_1244_946-710.jpg
call :setTime !t0! !time!
SET t1=!time!
:setTime
Setlocal EnableDelayedExpansion
SET t0=%1
SET t1=%2
echo !t0! !t1!
pause
SET /a m1 = !t0:~3,2!
SET /a s1 = !t0:~6,2!
SET /a s = !s1!*100
SET /a c = !t0:~9,2!
SET /a c = "!c!-((!c!/10)*4)"
SET /a d1 = !s!+!c!
echo !s!+!c! = !d1!
echo !d1!
echo !t1!
SET /a m2 = !t1:~3,2!
SET /a s2 = !t1:~6,2!
if "!m2!" GTR "!m1!" (
IF "!s2!" LSS "!s1!" (
REM e.g. s1=20, s2=04 =>
SET /a s2_cor = 60-!s1!+!s2!
echo Correction: s2: !s2!
SET /a s2_cor = "!s2!+60*(!m2!-!m1!)"
) ELSE (
SET /a s2_cor = "!s2!+60*(!m2!-!m1!-1)"
)
SET /a s2 = "!s2!+!s2_cor!"
)
SET /a s = !s2!*100
echo s2:!s2! , s:!s!
SET /a c = !t1:~9,2!
SET /a c = "!c!-((!c!/10)*4)"
SET /a d2 = !s!+!c!
echo !s!+!c! = !d2!
SET /a delay = !d2!-!d1!
echo Delay:!delay!
pause
endlocal
exit /b
Echo Working proxy ... !proxy!
)
)
if NOT !asterisk!==1 (
echo .
echo Asterix not set
echo .
exit
)
pause