Re: exit /b does not work properly in subroutines



Phil

Thanks for input but this is not what I need: I should be able to quit
entire batch from within subprogram conditionally.
Also I do not understand why simple documented by Microsoft function ("exit
/b") does not work as expected.

Martin

"Phil Robyn" <phil_robyn@xxxxxxxxxxx> wrote in message
news:qZqdnY5Ki7AY3vzZnZ2dnUVZ_sadnZ2d@xxxxxxxxxxxxxx
Martin Rakhmanov wrote:
Hello

According to MSFT documentation (help exit) I expect "exit /b 1" called
within a batch to exit current batch and set ERRORLEVEL to 1. But this
does
not work when I call exit /b in a subroutine - see attached batch. Why?
I
am running Windows Server 2003 SP1.

Martin




How about this version?

- - - - - - - begin screen capture WinXP MCE 2005 SP2 - - - - - - -
=====begin c:\cmd\demo\sample.cmd ====================
01. @echo off
02. setlocal
03. set exit=goto :EOF
04. call :MyLabel %1
05. %exit%
06. echo This line should never be reached
07.
08. goto :EOF
09.
10. :MyLabel
11.
12. if NOT "%~1"=="unknownoption" (
13. echo Hello from subprogram
14. set exit=exit /b 1
15. goto :EOF
16. )
=====end c:\cmd\demo\sample.cmd ====================
- - - - - - - end screen capture WinXP MCE 2005 SP2 - - - - - - -


--
Phil Robyn
University of California, Berkeley


.



Relevant Pages

  • Re: exit /b does not work properly in subroutines
    ... How to lose a war in Iraq ... and exit /b 1 respectively). ... It either exits a shelled batch or cmd.exe, ... echo This line should never be reached ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: exit /b does not work properly in subroutines
    ... How do I then exit entire batch from subprogram and set ... echo %errorlevel% ... echo This line should never be reached ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: CreateProcess not working as doc specifies.
    ... > to modify the batch files to make it work. ... simply setting exit at the end causes the terminal window to ... Hector Santos, Santronics Software, Inc. ... BOOL MakeSkeleton(const char *szTemp, const char *szClient) ...
    (microsoft.public.win32.programmer.kernel)
  • Re: exit /b does not work properly in subroutines
    ... Also why exit without /b switch exits entire batch, ... echo This line should never be reached ... within a batch to exit current batch and set ERRORLEVEL to 1. ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: exit /b does not work properly in subroutines
    ... I see - /b switch is required to exit batch. ... echo This line should never be reached ... within a batch to exit current batch and set ERRORLEVEL to 1. ...
    (microsoft.public.win2000.cmdprompt.admin)

Loading