Windows batch exit code / errorlevel

hi… i just made a simpel batch script for our client-systems.

i wanted to give an error-output to the user, but it never changes errorlevel despite of real error.
for example if the REST server is not reachable, the backup prozess should exit with errorcode not 0.

but it seems i always get a 0
any idea on that?

@echo off
REM #########################################################
REM #  how to use this batch file:                          #
REM #  - restback.cmd init      |  to initialize repo       #
REM #  - restback.cmd           |  to start backup          #
REM #  - restback.cmd help      |  to show more commands    #
REM #  ---------------------------------------------------  #
REM #  each file/folder on a seperate line in:              #
REM #  - restinclude.txt        | to backup                 #
REM #  - restexclude.txt        | to exclude from backup    #
REM #########################################################

REM ############################################
REM #  config                                  #
REM ############################################

SET RESTIC_USER=user
SET RESTIC_PASSWORD=password

REM ############################################
REM #  config - not necessary                  #
REM ############################################
SET RESTIC_REPO=repo
SET RESTIC_SERVER=sub.domain.tld
SET RESTIC_PORT=443
SET RESTIC_INCLUDE="%~dp0restinclude.txt"
SET RESTIC_EXCLUDE="%~dp0restexclude.txt"
SET RESTIC_DO=backup --files-from %RESTIC_INCLUDE% --exclude-file=%RESTIC_EXCLUDE%
SET RESTIC_COMMAND="%~dp0restic_0.9.6_windows_386.exe" -r rest:https://%RESTIC_USER%:%RESTIC_PASSWORD%@%RESTIC_SERVER%:%RESTIC_PORT%/%RESTIC_USER%%%2F%RESTIC_REPO%

REM ############################################
REM #  check for parameter:                    #
REM #  - no parameter = default backup         #
REM #  - repo is always given by config above  #
REM ############################################
IF [%1] == [] ( 
	@cmd /c
	echo:
	echo #########################################################################
	echo #                                                                       #
	echo #  Backup wird gestartet                                                #
	echo #  Warte bis das Backup fertig ist!                                     #
	echo #  Dieses Fenster schließt sich automatisch, wenn kein Fehler passiert  #
	echo #                                                                       #
	echo #########################################################################
	echo:
	echo:
	echo:-------------------------------------------------------------------------
	echo:
	%RESTIC_COMMAND% %RESTIC_DO%
		IF %ERRORLEVEL% NEQ 0 ( 
			echo:
			echo:-------------------------------------------------------------------------
			echo:
			echo #########################################################################
			echo #                                                                       #
			echo #  Problem beim anfertigen des Backups.                                 #
			echo #  Kontaktiere einen Administrator!                                     #
			echo #                                                                       #
			echo #  Fehlercode: %ERRORLEVEL%                                                        #
			echo #                                                                       #
			echo #########################################################################
		) ELSE (
			echo:
			echo:-------------------------------------------------------------------------
			echo:
			echo #########################################################################
			echo #                                                                       #
			echo #  Backup fertig                                                        #
			echo #                                                                       #
			echo #########################################################################
			timeout /T 10
		)
) ELSE ( 
	%RESTIC_COMMAND% %1 %2 %3 %4 %5 %6 %7
)

Related? https://github.com/restic/restic/issues/956

seems so… thx a lot… the set -o pipefail seems to do the trick
hahaha… lol… nope… this was for linux bash scripts… it “worked” here, because itself generated errorcode 1.

my fault =)

edit:
Any windows-foo-expert in here?

@echo off
SET COMMAND_A=restic_0.9.6_windows_386.exe -r rest:https://user.pass@sub.domain.tld:443/user%%2Frepo stats
SET COMMAND_B=dir z:

IF [%1] == [] (
	echo:
	%COMMAND_A%
	echo test 1: with if - error: %errorlevel%
) ELSE ( 
	echo:
	%COMMAND_B%
	echo test 2: with if - error: %errorlevel%
)

echo:
echo:--------------------------------------------------------------------------------------------------------------------------------------------------
echo:
%COMMAND_A%
echo:
echo test 3: without if - error: %errorlevel%
echo:

first run (without parameter):

C:\>script.cmd

Fatal: unable to open config file: client.Head: Head https://user.pass@sub.domain.tld:443/user%2Frepo/config: dial tcp: lookup sub.domain.tld: no such host
Is there a repository at the following location?
rest:https://user.pass@sub.domain.tld:443/user%2Frepo
test 1: with if - error: 0

--------------------------------------------------------------------------------------------------------------------------------------------------

Fatal: unable to open config file: client.Head: Head https://user.pass@sub.domain.tld:443/user%2Frepo/config: dial tcp: lookup sub.domain.tld: no such host
Is there a repository at the following location?
rest:https://user.pass@sub.domain.tld:443/user%2Frepo

test 3: without if - error: 1

second run (with parameter):

second run (with parameter):
C:\>script.cmd foo

Das System kann den angegebenen Pfad nicht finden.
test 2: with if - error: 0

--------------------------------------------------------------------------------------------------------------------------------------------------

Fatal: unable to open config file: client.Head: Head https://user.pass@sub.domain.tld:443/user%2Frepo/config: dial tcp: lookup sub.domain.tld: no such host
Is there a repository at the following location?
rest:https://user.pass@sub.domain.tld:443/user%2Frepo

test 3: without if - error: 1

found the solution… windows is “special”…