1

I want to write a Windows batch script to find the error message from an output file.

I have written some sample to code to create the output file and to search for the ERROR MESSAGE "ERROR".

@eacho on
pdm_webstat >> pdm_webstat.txt
find /c "ERROR" pdm_webstat.txt

The output of the pdm_webstat is as follows:

PDM_Webstat: Invoked at 08/20/2013 13:01:56

=========================================
Report from Webengine: web:wsp
=========================================
Cumulative sessions so far = 0
Most sessions at a time    = 0
Currently active sessions  = 0

=========================================
Report from Webengine: web:local
=========================================
ERROR : web engine failed to run

Now I am searching for the string ERROR in the output file as follows:

find /c "ERROR" pdm_webstat.txt

If the error message is found I have to run the some set of statements.

Can any one help me how to write a script of the above requirement?

0

1 Answer 1

3

you can try this:

find /i "ERROR" pdm_webstat.txt >nul 2>&1 && (
    echo "ERROR" found
    REM run your Java program here
)  ||  (
    echo "ERROR" not found
    REM command if "ERROR" not found
)
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you,the code is perfect, But i am looking, if error found in the text file i have to run the same sample java program.
you can replace echo "ERROR" ... with another program call or whatever you want.
Thank you, I have a java project that i need to execute based on the 'ERROR message' in Outputfile. Is it possible to return a a value to a variable and then use that varible in IF clause. IF Error Found( run the java project )
@user2700968 this works like a IF / ELSE clause, please see my edit.

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.