在后台运行计时器的批处理。如何?

发布于 2024-10-06 06:15:30 字数 157 浏览 0 评论 0原文

我想知道是否有一种方法可以制作一个使用计时器脚本(例如 TIMEOUT 命令)的批处理文件,并在计时器运行时使批处理文件执行其他进程。但当计时器用完时,则退出。 (或执行另一个小过程)我知道这意味着批处理文件必须同时运行多个进程,我只是想知道它是否可能以某种方式实现。

有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

指尖上的星空 2024-10-13 06:15:30

您可以使用start /b cmd /c myTimeout.bat
这将在同一窗口中启动一个新应用程序(启动/?)

使用此机制,您应该能够同时执行多个作业

编辑
对于简单的超时来说,这似乎有点过大。
对于 6 秒的超时,您可以使用类似的东西

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

,它更适合真正的并行作业,例如游戏的显示作业和按键输入作业。

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.

脸赞 2024-10-13 06:15:30

修改了 jeb 的代码,使其可以工作:

@echo off
set /A startMs=10*%time:~9,2%+1000*%time:~6,2%+60000*%time:~3,2%+3600000*%time:~0,2%
REM the 6000 in the next line is how many milliseconds of a delay you want
set /a timeoutAt=%startMs%+6000
:loop
REM 'passive' code here:

REM Test if the timeout is reached
2>NUL set /A nowMs=10*%time:~9,2%+1000*%time:~6,2%+60000*%time:~3,2%+3600000*%time:~0,2%
if /I %nowMs% GTR %timeoutAt% goto leaveTheLoop
goto loop

:leaveTheLoop
REM do the things you want to do when the timer ends

modified the code from jeb so that it works:

@echo off
set /A startMs=10*%time:~9,2%+1000*%time:~6,2%+60000*%time:~3,2%+3600000*%time:~0,2%
REM the 6000 in the next line is how many milliseconds of a delay you want
set /a timeoutAt=%startMs%+6000
:loop
REM 'passive' code here:

REM Test if the timeout is reached
2>NUL set /A nowMs=10*%time:~9,2%+1000*%time:~6,2%+60000*%time:~3,2%+3600000*%time:~0,2%
if /I %nowMs% GTR %timeoutAt% goto leaveTheLoop
goto loop

:leaveTheLoop
REM do the things you want to do when the timer ends
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文