Venkat
Venkat

Reputation: 307

Create a batch script to find the error message from output file, if error message found it has to run a java program

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?

Upvotes: 1

Views: 1568

Answers (1)

Endoro
Endoro

Reputation: 37569

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
)

Upvotes: 3

Related Questions