1

我有一个每天由预定的批处理文件启动的过程。如果出现错误,我需要内置错误处理以重新启动该过程。大多数时候一切都很好,但我每个月都会遇到一次超时错误,这是不可避免的。该进程不会向 bat 文件输出错误级别,因此我需要能够解析输出文件以确定进程是否需要重新启动。

我尝试使用该FOR /F函数将第 12 行的内容作为变量传递给IF语句,但我没有成功。我显然可以跳到第 12 行,但接下来我要处理其余行的标记。有没有人有任何建议我可以尝试?

一切正常时输出文件:

(为便于阅读添加了行号)

1  Pricing Script
2   
3  ________________________________________________________________________ 
4
5  Retrieve Prices
6
7  Date of price file: 070912
8  Regular only 
9  Connecting to server intdata.com
10 TCP/IP connection established
11  
12 TySymb          Interactive Data
+400 more lines

出错时的输出文件:

1  Pricing Script
2  
3  ________________________________________________________________________ 
4 
5  Retrieve Prices
6  
7  Date of price file: 071012
8  Regular only 
9  Connecting to server intdata.com
10 TCP/IP connection established
11 Time Out
12 General Time Out. The User ID and/or Password might be incorrect.
4

2 回答 2

2

我只需使用 FIND 或 FINDSTR 在输出中查找错误消息。我不会担心行号。

find "General Time Out. The User ID and/or Password might be incorrect." "yourFile.log" && (
  echo Timeout occurred, you must put code here to restart
)

或者

findstr /c:"General Time Out. The User ID and/or Password might be incorrect." "yourFile.log" && (
  echo Timeout occurred, you must put code here to restart
)
于 2012-07-11T20:36:10.510 回答
0

这将只测试给定字符串的文件的第 12 行:

@echo off
for /f "skip=11 tokens=*" %%i in (your_log_filename) do (
 echo %%i | find "General Time Out" >nul
 goto check
)

:check
if errorlevel 1 (echo No Timeout occured!) else (echo Timeout occured)
于 2012-07-11T18:54:12.303 回答