I have a control_script.cmd that works as it is but is a little hard to read. Basically, I want to quit my script when the first program returns an error.
set text=converting something...
call %libdir%\1_convert_xlsx.cmd
set rvalue=%errorlevel%
call :check_errorlevel !rvalue! "!text!"
if !rvalue! geq 1 goto :my_error_handler
set text=loading something...
call %libdir%\2_load_something.cmd
set rvalue=%errorlevel%
call :check_errorlevel !rvalue! "!text!"
if !rvalue! geq 1 goto :my_error_handler
:check_errorlevel
set rvalue=%~1
set text=%~2
echo do something with rvalue and text
exit /b 0
:my_error_handler
exit /b 1
it would be much nicer if I could move the if-clause into the check_errorlevel part, like
call %libdir%\1_convert_xlsx.cmd
call :check_errorlevel %errorlevel% "converting something..."
call %libdir%\2_load_something.cmd
call :check_errorlevel %errorlevel% "loading something..."
:check_errorlevel
set rvalue=%~1
set text=%~2
echo do something with rvalue and text
if !rvalue! geq 1 goto :my_error_handler
exit /b 0
:my_error_handler
exit /b 1
But here I face the issue that :my_error_handler is not defined within :check_errorlevel and I do not see any other way to go directly from :check_errorlevel to the end of my cmd. Is there any?
Best regards, Peter