Command line 如果命令提前完成,如何自动停止超时计数?

Command line 如果命令提前完成,如何自动停止超时计数?,command-line,timeout,Command Line,Timeout,在我的脚本中,我使用timeout设置执行命令的最大时间限制 start 7z.exe t %%f if errorlevel 2 (DEL %%f & echo File broken. Reload File!) timeout /t 3600 如果执行时间超过一小时,则超时将中断执行。这工作没有任何问题 但是,如果命令在时间戳之前完成,我怎么能忽略超时计数并自动执行脚本呢?正如当前编写的那样,没有/W开关不会影响/更改错误级别证明: ==> hfhgf 'hfhgf' is

在我的脚本中,我使用timeout设置执行命令的最大时间限制

start 7z.exe t %%f
if errorlevel 2 (DEL %%f & echo File broken. Reload File!)
timeout /t 3600
如果执行时间超过一小时,则超时将中断执行。这工作没有任何问题

但是,如果命令在时间戳之前完成,我怎么能忽略超时计数并自动执行脚本呢?

正如当前编写的那样,没有
/W
开关不会影响/更改
错误级别
证明

==> hfhgf
'hfhgf' is not recognized as an internal or external command,
operable program or batch file.

==> echo %errorlevel%
9009

==> start "" ping.exe localhost

==> echo %errorlevel%
9009

==> start "" /W ping.exe localhost

==> echo %errorlevel%
0
使用
/W
/WAIT
开关(启动应用程序并等待其终止)并删除所有
超时
行,如下所示。我猜您的代码片段可能是
do
for循环的一部分:

for %%f in (*.zip) do (
  (call )
  start "" /W 7z.exe t "%%f"
  if errorlevel 2 (
     echo File broken. Reload File %%f
     DEL "%%f"
  )
)
关于
(电话)
说明,请参见Dave Benham对以下内容的回复:

如果要强制errorlevel为0,则可以使用 完全不直观,但非常有效的语法:
(call)
。空间 售后服务至关重要。如果要将errorlevel设置为1,请 可以使用
(调用)
。之后没有任何空间是至关重要的 打电话