DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: I need a batch command to stop the process and exit immediately when it finds th  (Read 7,647 times)

johnny09033

  • Participant
  • Joined in 2017
  • *
  • Posts: 5
I need a batch command to stop the process and exit immediately when it finds this error:
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


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

Code
:: Error exit codes
SET /A ERROR_UNKNOWN=-1
SET /A ERROR_OK=0
SET /A ERROR_NO_BOOKMARK_FOUND=1
SET /A ERROR_NO_MORE_DICTS=2
SET /A ERROR_FINDSTR_UNKNOWN_EXIT_CODE=3

and

1'st exit situation:
Code
:: 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
) 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
:: 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
connection error



THANK YOU!

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Seems an interesting question.
Perhaps you can do in AHK. There are many experts here in this script language...

Original address: https://www.donationcoder.com/forum/index.php?topic=44066.0