Obviously, I can run an EXE program which is known to always return zero
but I'm hoping for a script command solution.
A answer which may apply in some cases is that you can set ERRORLEVEL
upon return from a script subroutine with the EXIT command.
CALL :subroutine
IF ERRORLEVEL 1 (
REM do something
)
GOTO :EOF
:subroutine
REM do something that sets RC to a value
EXIT /B %RC%
After the call, ERRORLEVEL will be set to the value of RC.
--
Norm
To reply, change domain to an adult feline.
Try CD>NUL or VER>NUL to reset errorelvel back to zero.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
>I discovered, somewhat to my surprise, that a statement
> SET VAR=
>causes ERRORLEVEL to be set to one (1). However,
> SET VAR=value
>does not reset ERRORLEVEL, if it is non-zero, back to zero. Is there any
>script command that does set ERRORLEVEL to zero?
I was lucky, the first command I tried worked. :)
===[screen capture]===
M:\>set a=
M:\>echo %errorlevel%
1
M:\>cd .
M:\>echo %errorlevel%
0
===[screen capture]===
38} How can I set and test the errorlevel within a script file?
http://www.netikka.net/tsneti/info/tscmd038.htm
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/> ; FI-65101, Finland
Useful CMD script tricks http://www.netikka.net/tsneti/info/tscmd.htm
> Norman Bullen <no...@BlackKittenAssociates.com> wrote:
>
>> Is there any script command that does set ERRORLEVEL to zero?
>
>
> 38} How can I set and test the errorlevel within a script file?
> http://www.netikka.net/tsneti/info/tscmd038.htm
>
> All the best, Timo
>
Thanks to all.
Hi Norman,
this is only the case if VAR isn't defined.
if defined VAR set VAR=
will circumvent the errorlevel being set.
> However,
> SET VAR=value
> does not reset ERRORLEVEL, if it is non-zero, back to zero.
I guess this is by design, if simple commands like echo and set would reset
errorlevel the error handling gets more complicated.
If you want to display and save the errorlevel in a var it might be reset
otherwise.
> Is there any
> script command that does set ERRORLEVEL to zero?
>
I like foxidrives "cd ." as it does in fact nothing.
Greetings
Matthias
Rename your batch from .bat to .cmd and it will reset the errorlevel.
However, commands that _are_ supposed to return errorlevels, appear to
reset as expected. Try e.g.
@echo off & setlocal enableextensions
set var=
echo %%errorlevel%%=%errorlevel%
echo.@exit /B ^0>tmp$$$.cmd
call tmp$$$
echo %%errorlevel%%=%errorlevel%
for %%f in (tmp$$$.cmd) do if exist %%f del %%f
goto :EOF
You'll get
%errorlevel%=1
%errorlevel%=0
> Rename your batch from .bat to .cmd and it will reset the errorlevel.
While obviously true on testing, and interesting, I don't know where
this would and should take us. SET is not among the commands/programs
that is documented to return errorlevels. The same distinction does not
seem to manifest with commands that actually are supposed to return it.
If it did, the choice between .BAT and .CMD would gain a new significance.