Exit script with errorcode from (sub)section

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
netlord
Posts: 1
Joined: 05 Jul 2017 10:04

Exit script with errorcode from (sub)section

#1 Post by netlord » 06 Jul 2017 02:56

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.

Post Reply