1

スケジュールされたバッチ ファイルによって毎日開始されるプロセスがあります。エラーが発生した場合にプロセスを再起動するには、エラー処理を組み込む必要があります。ほとんどの場合、すべてがうまく機能しますが、月に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 に答える