Batch that runs a timer in the background. How?

左心房为你撑大大i 提交于 2019-12-11 03:24:26

问题


I was wondering if theres a way to make a batch file that uses a timer script (such as the TIMEOUT command) and while the timer is running, make the batch file do other processes. But when the timer runs out, then exit. (Or carry out another small process) I know this means that te batch file would have to run multiple processes at once, i just want to know if its possible somehow.

Any ideas?


回答1:


You can use start /b cmd /c myTimeout.bat
This starts a new application in the same window (start /?)

With this mechanism you should be able do multiple jobs at the same time

EDIT For a simple timeout this seems to be a bit oversized. For a timeout of 6 seconds you can use something like

set startTime=%time%
call :timeToMs startMs startTime
set /a timeoutAt=startMs + 6000
:loop
... wait for something, like a file is created, or a CD is inserted
if job_is_ready goto :leaveTheLoop
REM Test if the timeout is reached
set currentTime=%time%
call :timeToMs nowMs currentTime
if nowMs GTR timeoutAt goto :leaveTheLoop
goto :loop

:leaveTheLoop

It fits better for real parallel jobs, like a display job and a key-input job for a game.



来源:https://stackoverflow.com/questions/4340883/batch-that-runs-a-timer-in-the-background-how

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!