1

I have a process that is kicked off by a scheduled batch file daily. I need to have error handling built in to restart the process if there is an error. All works great most days but I get a time out error once a month or so that is unavoidable. The process does not output an errorlevel to the bat file so I need to be able to parse the output file to determine if the process needs to restart.

I tried using the FOR /F function to pass the contents of line 12 as a variable to use in an IF statement but I have been unsuccessful. I can obviously skip to line 12 but then I am left dealing with the tokens of the remaining lines. Does anyone have any suggestions that I could try?

Output file when all is well:

(Line Numbers Added for Readability)

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

Output file when there is an error:

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.
2
  • So you just want the 12th line in the output file? Commented Jul 11, 2012 at 16:39
  • That's one way to approach it, if I can get that I should be set. Commented Jul 11, 2012 at 16:55

2 Answers 2

2

I would simply look for the error message in the output using FIND or FINDSTR. I wouldn't worry about the line number.

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
)

or

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
)
Sign up to request clarification or add additional context in comments.

2 Comments

+1. Neat. But how do you know that that's the only possible error message?
@EitanT - I don't obviously :) But as long as all possible error messages are known (or at least a distinct fragment) then FINDSTR can be used with multiple /C arguments, one per message. Or FINDSTR could be used with regular expressions to match some distinct error message pattern.
0

This will test only line 12 of your file for a given string:

@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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.