Search for a string and perform an action

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
thegeek
Posts: 1
Joined: 01 Jun 2008 20:46
Location: Calgary

Search for a string and perform an action

#1 Post by thegeek » 01 Jun 2008 20:56

Hello all,
I have an application that when it finishes creates some log files.
I need to do a search in one of the log files (text files) for the words "Success" or "Failure".
If I find "Success" then I run a message box informing the users that the application completed successfully and if I find "Failure", the message box informs the users it failed.
I like to do this in a simple dos script as I am running the actual application by a dos script.
Any help is much appreciated.
Thanks...

greenfinch
Posts: 36
Joined: 17 Jul 2008 07:37

#2 Post by greenfinch » 17 Jul 2008 09:57

Do you mean something like this?

Code: Select all

setlocal
set inputfile=%1
for /f %%a in ('findstr Success %inputfile%') do set foundS=%%a
if [%foundS%]==[] (set success=0) ELSE (set success=1)

for /f %%a in ('findstr Failure %inputfile%') do set foundF=%%a
if [%foundF%]==[] (set failure=0) ELSE (set failure=1)

echo %success%
echo %failure%

Post Reply