I need a batch command to stop the process and exit immediately when it finds this error

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
raspberry109
Posts: 29
Joined: 07 Jun 2017 23:40

I need a batch command to stop the process and exit immediately when it finds this error

#1 Post by raspberry109 » 01 Jul 2017 02:10

I need a batch command to stop the process and exit immediately when it finds this error:

Code: Select all

connection error

the batch works with a certain tool and these are some benchmarks if they help something
The script I own closes the process in these situations and I want someone to help me add a new situation


Code: Select all

:: Controll stopping
:: (1=enable,0=disable;)


and

1'st exit situation:

Code: Select all

:: Check if the file exists
IF NOT EXIST "%filep%" (
   ECHO File "%filep%" was not found. Assuming we ran out.
   ECHO We did not find.
   SET /A errno=%ERROR_NO_MORE_DICTS%
   GOTO END
)


Another exit situation:

Code: Select all

) ELSE (
   :: tool did not run ok. No ideea why. The multitude of checks should have
   :: prevented this.
   ECHO %tool% exited with non-zero exit code. No ideea why. Contact dev.
   SET /A errno=%ERROR_UNKNOWN%
   GOTO END
)


The 3'rd situation:

Code: Select all

:: Call command
%composedcmd%

:: Check if we ran ok
IF /I "%ERRORLEVEL%" EQU "%ERROR_OK%" (
   :: Check if we found mamammia
   FIND "Discovered mamammia" "%tooloutfile%" >NUL 2>&1 && (
      ECHO mamammia.
      GOTO END



I want to add new exit,so when finds this error EXIT:

Code: Select all

connection error


THANK YOU!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: I need a batch command to stop the process and exit immediately when it finds this error

#2 Post by aGerman » 02 Jul 2017 08:49

raspberry109 wrote:I want to add new exit,so when finds this error EXIT:

Where would it be found? In "%tooloutfile%"?
You may replace FIND with FINDSTR in your third snipped in order to be able to check for several strings at once.

Code: Select all

FINDSTR /c:"Discovered mamammia" /c:"connection error" "%tooloutfile%" >NUL 2>&1 && (

Steffen

Post Reply