Call a second batch which in turn you explicitly "exit /B errorlevel"
See what is not in the windows help:
exit /?
--
Greetings
Matthias________________________________________
For help on nt commands enter in a cmd window:
W2K>HH windows.chm::ntcmds.htm XP>HH ntcmds.chm
That's unix syntax
gawk "BEGIN{exit(1)}"
is a Windows version.
There are a couple of utilities in one of the GNU Windows utilities
collections (Sh-Utils) at
<http://sourceforge.net/project/showfiles.php?group_id=23617> that
contain true and false utilities returning 0 and 1 respectively.
Since you appear to be Unix aware, you might be interested in many of
the packages on that page.
T.E.D. (tda...@gearbox.maem.umr.edu)
SPAM filter: Messages to this address *must* contain "T.E.D."
somewhere in the body or they will be automatically rejected.
> Call a second batch which in turn you explicitly "exit /B errorlevel"
No need for an external batch:
:::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
call :seterr
echo errorlevel: %errorlevel%
goto :eof
:seterr
exit /b 10
:::::::::::::::::::::::::::::::::::::::::::::::::::::::
NOTE: set behave different in a .bat and .cmd file:
:::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: save this code as a.bat and b.cmd and execute both
@echo off
set a=
call :seterr
echo errorlevel: %errorlevel%
set a=
echo errorlevel: %errorlevel%
set a=
call :seterr
echo errorlevel: %errorlevel%
set a=irgendwas
echo errorlevel: %errorlevel%
set a=igendwas
call :seterr
echo errorlevel: %errorlevel%
set a=
echo errorlevel: %errorlevel%
goto :eof
:seterr
exit /b 10
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off & setlocal enableextensions
:: Requires G(nu)AWK
gawk 'BEGIN{exit 2}'
for %%e in (0 1 2 3 4 5 6 7 8 9) do (
if %errorlevel% EQU %%e echo The errorlevel is %%e)
goto :EOF
@echo off & setlocal enableextensions
echo.@exit /B ^2>tmp$$$.cmd
call tmp$$$
for %%e in (0 1 2 3 4 5 6 7 8 9) do (
if %errorlevel% EQU %%e echo The errorlevel is %%e)
for %%f in (tmp$$$.cmd) do if exist %%f del %%f
goto :EOF
BTW, note the ^2 to avoid the script from mistaking if for a handle.
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Useful script files and tricks ftp://garbo.uwasa.fi/pc/link/tscmd.zip
>Matthias Tacke wrote:
>
>> Call a second batch which in turn you explicitly "exit /B errorlevel"
>
>No need for an external batch:
>
Yes, I should have known, that the (internal) call also opens another
cmd. I focused to much on the "ending the batch" of exit.
That is an inventive solution that you presented. However, sometimes
an external batch solution is much simpler, at least for the reader
to follow. Furthermore, an extennal batch most often can be easioly
created by the original batch and then deleted also by the original
batch. Given in an earlier posting of mine on this subject.
(snip)
> :::::::::::::::::::::::::::::::::::::::::::::::::::::::
> :: save this code as a.bat and b.cmd and execute both
That's also two batches.
Please understand that I am not minimizing your fine, inventive
solution. I am just pointing out that often the seemingly less
orthodox solution is more convenient and more obvious in its logic.
Could be made more general as in this example:
> :::::::::::::::::::::::::::::::::::::::::::::::::::::::
> @echo off
> call :seterr 10
> echo errorlevel: %errorlevel%
> goto :eof
>
> :seterr
> exit /b %1
> :::::::::::::::::::::::::::::::::::::::::::::::::::::::
/Al
Yes, but the linecount, the linecount.
> Please understand that I am not minimizing your fine, inventive
> solution. I am just pointing out that often the seemingly less
> orthodox solution is more convenient and more obvious in its logic.
Yes, this is always a possibility. I just think that, in this case, the
simpler solution is, well, simpler.
/Al
And as we have learned here a few weeks ago, no call is necessary
at all:
echo.>nul|exit /b 16
echo %errorlevel%
Now _that_ is an excellent, concise solution. Certainly worth a
Google pointer link.
Clever combined. I like it. Pretty short.
The redirection is redundant and may be omitted.
So this gives the same result:
echo.|exit /b 16
"Herbert Kleebauer" <kl...@unibwm.de> wrote in message news:3FE5DAA2...@unibwm.de...
Why not:
cmd/cexit/b16
echo %errorlevel%