Batch that runs a timer in the background. How?

2019-07-17 17:35发布

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条回答
我想做一个坏孩纸
2楼-- · 2019-07-17 17:57

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.

查看更多
登录 后发表回答