Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 连续循环命令(不暂停)X秒_Loops_Batch File - Fatal编程技术网

Loops 连续循环命令(不暂停)X秒

Loops 连续循环命令(不暂停)X秒,loops,batch-file,Loops,Batch File,目前,我正在处理一个批处理文件,以连续执行一个命令X秒,在X秒过后,我希望使用goto函数重定向它 这是最接近我所希望的代码 :MainMenu set yourno= set /p yourno=Input your number: set /p looptime=Input time: goto PerformCalc :PerformCalc set /a yourno= %yourno%+1 timeout 1 set /a looptime=%looptime%-1 goto

目前,我正在处理一个批处理文件,以连续执行一个命令X秒,在X秒过后,我希望使用goto函数重定向它

这是最接近我所希望的代码

:MainMenu
set yourno=
set /p yourno=Input your number:
set /p looptime=Input time:
goto PerformCalc

:PerformCalc
 set /a yourno= %yourno%+1
 timeout 1
 set /a looptime=%looptime%-1
 goto CheckLoop

:CheckLoop
if %looptime% equ 0 goto FinishScreen
goto PerformCalc

:FinishScreen
echo Congratulations Your no. is %yourno%
echo Operations completed in %looptime% seconds
pause
以上代码的问题是,如果我将循环时间设置为10秒,它将只执行10个操作。但这不是我打算做的事。我意识到我已经在我的代码中输入了超时1,并且每过1秒就减少1。然而,这是因为我无法找到一种方法来连续循环代码10秒,而不使用timeout 1,从而暂停代码,只执行10个操作

如果你仍然不明白我的意思,下面是代码应该执行的逻辑流,比如说,用户输入的循环时间为10秒

For Time=10seconds
Do {set /a yourno= %yourno%+1 continuously}
After Time of 10 seconds has elapsed redirect to :FinishScreen
谢谢你的帮助

@echo off
setlocal

rem Get end time
set seconds=10
for /F "tokens=1-4 delims=:.," %%a in ("%time: =0%") do set /A "endTime=1%%a%%b%%c%%d+seconds*100"

echo Start: %time%
echo Working %seconds% seconds, please wait...

set yourNo=0
:loop
set /A yourNo+=1

rem Check if end time had been reached
for /F "tokens=1-4 delims=:.," %%a in ("%time: =0%") do if 1%%a%%b%%c%%d lss %endTime% goto loop

echo End:   %time%
echo This program could complete %yourNo% loops in 10 seconds

如果处理时间超过午夜,此方法可能会失败,但如果需要,只需简单调整即可解决此问题…

Hi。虽然我找到了另一种方法,但我要感谢你的努力。你能解释一下这是怎么回事吗?do set/A endTime=1%%A%%b%%c%%d+秒*100