Re: exit /b does not work properly in subroutines
- From: "Martin Rakhmanov" <mrakhmanov@xxxxxxxxxxxxx>
- Date: Wed, 10 May 2006 13:18:43 +0400
Please have a look at two batch files: they only differ in one line (exit
and exit /b 1 respectively). So why the batches behave differently?
"David Candy" <.> wrote in message
news:uLeus7AdGHA.5116@xxxxxxxxxxxxxxxxxxxxxxx
It doesn't. It either exits a shelled batch or cmd.exe, just like all dos
batch files expect..
--
--------------------------------------------------------------------------------------------------
How to lose a war in Iraq
http://webdiary.com.au/cms/?q=node/1335#comment-48641
=================================================
"Martin Rakhmanov" <mrakhmanov@xxxxxxxxxxxxx> wrote in message
news:egD3bsAdGHA.3792@xxxxxxxxxxxxxxxxxxxxxxx
Also why exit without /b switch exits entire batch, i.e. does exactly what
I
need (but does not set errorlevel)?
"Martin Rakhmanov" <mrakhmanov@xxxxxxxxxxxxx> wrote in message
news:%23xMZrnAdGHA.4532@xxxxxxxxxxxxxxxxxxxxxxx
Yes, you are right. How do I then exit entire batch from subprogram and
set errorlevel?
"David Candy" <.> wrote in message
news:%23xx4HdAdGHA.1208@xxxxxxxxxxxxxxxxxxxxxxx
It is doing what is expected. It is exiting the second bat file started
with call. You are running a batchfile twice.
add this line
echo %errorlevel%
echo This line should never be reached
See Call's help.
--
--------------------------------------------------------------------------------------------------
How to lose a war in Iraq
http://webdiary.com.au/cms/?q=node/1335#comment-48641
=================================================
"Martin Rakhmanov" <mrakhmanov@xxxxxxxxxxxxx> wrote in message
news:eN7g0RAdGHA.1208@xxxxxxxxxxxxxxxxxxxxxxx
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
begin 666 sample2.cmd
M0&5C:&\@;V9F#0H-"F-A;&P@.DUY3&%B96P-"@T*96-H;R!4:&ES(&QI;F4@
M<VAO=6QD(&YE=F5R(&)E(')E86-H960-"@T*9V]T;R Z14]�H-"CI->4QA
M8F5L#0H-"FEF($Y/5" B)7XQ(CT](G5N:VYO=VYO<'1I;VXB("@-"B!E8VAO
M($AE;&QO(&9R;VT@<W5B<')O9W)A;0T*(&5X:70-"B!G;W1O(#I%3T8-"BD-
)"@T*( T*( T*
`
end
begin 666 sample.cmd
M0&5C:&\@;V9F#0H-"F-A;&P@.DUY3&%B96P-"@T*96-H;R!4:&ES(&QI;F4@
M<VAO=6QD(&YE=F5R(&)E(')E86-H960-"@T*9V]T;R Z14]�H-"CI->4QA
M8F5L#0H-"FEF($Y/5" B)7XQ(CT](G5N:VYO=VYO<'1I;VXB("@-"B!E8VAO
M($AE;&QO(&9R;VT@<W5B<')O9W)A;0T*(&5X:70@+V(@,0T*(&=O=&\@.D5/
..1@T**0T*#0H@#0H@#0H`
`
end
.
- Follow-Ups:
- Re: exit /b does not work properly in subroutines
- From: Martin Rakhmanov
- Re: exit /b does not work properly in subroutines
- References:
- exit /b does not work properly in subroutines
- From: Martin Rakhmanov
- Re: exit /b does not work properly in subroutines
- From: Phil Robyn
- Re: exit /b does not work properly in subroutines
- From: Martin Rakhmanov
- Re: exit /b does not work properly in subroutines
- From: Martin Rakhmanov
- Re: exit /b does not work properly in subroutines
- From: Martin Rakhmanov
- exit /b does not work properly in subroutines
- Prev by Date: Re: exit /b does not work properly in subroutines
- Next by Date: Re: exit /b does not work properly in subroutines
- Previous by thread: Re: exit /b does not work properly in subroutines
- Next by thread: Re: exit /b does not work properly in subroutines
- Index(es):
Relevant Pages
|