Page 1 of 1

Exit script with errorcode from (sub)section

Posted: 06 Jul 2017 02:56
by netlord
Hi there

I´m struggling now for a while and doesn´t get it.

I have this example script:

Code: Select all

@echo off & cls
:Main
setlocal ENABLEDELAYEDEXPANSION
setlocal ENABLEEXTENSIONS

  call :section_1
  call :section_2
  call :EndScript
 
REM ##################################--BOF--###################################
:section_1
echo :section_1_start & pause

   if exist 111.txt set errorlevel=2 & call :EndScript

echo :section_1_end & pause   
goto :EOF
REM ##################################--EOF--###################################

REM ##################################--BOF--###################################
:section_2
echo :section_2_start & pause

  if not exist 111.txt set errorlevel=3 & goto EndScript

echo :section_2_end & pause
goto :EOF
REM ##################################--EOF--###################################

REM ##################################--BOF--###################################
:EndScript
echo endscript_start & pause
::   echo on
      exit /b 1
::   echo off
echo endscript_end & pause   
goto :EOF
REM ##################################--EOF--###################################


The plan is to exit the script in the Line 34.
But this doesn´t exit the script, only the section. Without the /b the window will be closed.

How to write it do exit the script, but not to close the window?
Thanks.