Discussion:
WZZIP Errorlevels
(too old to reply)
YT
2004-11-30 17:47:57 UTC
Permalink
Hi,

I use WinZips command line utility to zip files. I have a batch file
that I run every night that backs up any changed files. It looks like
this:

wzzip.exe -^ -P -r -whs c:\changes.zip c:\projects -td1
If ErrorLevel 1 Goto Error

When there is an error it emails me telling me that. The problem is
that if there were no changed files it gives me this:
Error: No files were found for this action that match your criteria -
nothing to do.

And the "ErrorLevel 1" statement is true so I get emailed even though
there really isn't a problem. How can I tell when it is this error or
if its a more serious error? I really only want to get emailed when
the backup fails.

Thanks,
Reece
Norman L. DeForest
2004-12-01 13:40:15 UTC
Permalink
Post by YT
Hi,
I use WinZips command line utility to zip files. I have a batch file
that I run every night that backs up any changed files. It looks like
wzzip.exe -^ -P -r -whs c:\changes.zip c:\projects -td1
If ErrorLevel 1 Goto Error
When there is an error it emails me telling me that. The problem is
Error: No files were found for this action that match your criteria -
nothing to do.
And the "ErrorLevel 1" statement is true so I get emailed even though
there really isn't a problem. How can I tell when it is this error or
if its a more serious error? I really only want to get emailed when
the backup fails.
Does the documentation describe the different errorlevels generated for
the different errors? Apparently you have to be a registered WinZip user
to install the command-line add-on and I am not about to pay to register
it just to find out what the errorlevels are.

Errorlevels returned can be 0 to 255 (or be undefined if a program uses
the old terminate function instead of the advanced terminate function).

COMMAND.COM's "If ErrorLevel n" (where 'n' is a number from 0 to 255) can
be translated as "If ErrorLevel is greater than or equal to n".
Obviously, "If ErrorLevel 0" is always true.

To check for different errorlevels, check the higher numbers first.

For a fictional example, suppose that the errorlevel returned when no
matching files were found was 7 (since I don't know what the real
errorlevels are) and other, genuine errors returned values higher or lower
than that (but not 0). In that case, you would be able to use something
like this:

wzzip.exe -^ -P -r -whs c:\changes.zip c:\projects -td1
rem check for errorlevels 8 or higher:
if errorlevel 8 goto error
rem check for errorlevel 7
if errorlevel 7 goto noterror
rem check for errorlevels from 1 to 6
if errorlevel 1 goto error

rem Insert your code here for errorlevel 0 (no error reported)

goto done

:noterror
rem Insert your code here for the alleged error "No files were
rem found for this action that match your criteria -...",
rem errorlevel equal to 7
goto done

:error
rem Insert your code here for real errors.

:done

You can test all of the possible errorlevels returned by a specific run of
the program by using something like this:

wzzip.exe -^ -P -r -whs c:\changes.zip c:\projects -td1
if errorlevel 255 goto e255
if errorlevel 254 goto e254
if errorlevel 253 goto e253
if errorlevel 252 goto e252
...
... etc. etc.
...
if errorlevel 3 goto e3
if errorlevel 2 goto e2
if errorlevel 1 goto e1
echo errorlevel 0 (no error)
goto done
:e255
echo errorlevel 255
goto done
:e254
echo errorlevel 254
goto done
:e253
echo errorlevel 253
goto done
...
... etc. etc.
...
:e3
echo errorlevel 3
goto done
:e2
echo errorlevel 2
goto done
:e1
echo errorlevel 1
:done

or get the (now) free 4DOS command interpreter, see
http://www.chebucto.ns.ca/~af380/Tips.html#Tip001
and:
http://www.chebucto.ns.ca/~af380/4d.html
and you could then just use the following to print the errorlevel
returned:

wzzip.exe -^ -P -r -whs c:\changes.zip c:\projects -td1
echo errorlevel was %?

4DOS also allows redirection of error output so any error messages
that would otherwise go to the screen even with output redirection
on could be also redirected to a log file (as could the output of the
echo errorlevel was %?
command).

With 4DOS, errorlevels can also be checked for exact equality, greater
than a value or less than a value (or the inverse of those) and tests
can be combined:
if errorlevel eq 25 goto e25
if errorlevel lt 9 goto err0to9
if errorlevel eq 12 .OR. errorlevel eq 16 goto err12or16
To keep the errorlevel even if you want to run something else,
set a variable to the WinZip error code and then you can test
the variable even after running something else:
wzzip.exe -^ -P -r -whs c:\changes.zip c:\projects -td1
set wzerr=%?
something else
if "%wzerr" eq "6" anotherprogram
if "%wzerr" gt "5" yetanotherprogram
...
--
Norman De Forest http://www.chebucto.ns.ca/~af380/Profile.html
***@chebucto.ns.ca [=||=] (A Speech Friendly Site)
"O'Reilly is to a system administrator as a shoulder length latex glove
is to a veterinarian." -- Peter da Silva in the scary devil monastery
Matthias Tacke
2004-12-01 14:37:08 UTC
Permalink
Post by Norman L. DeForest
Does the documentation describe the different errorlevels generated for
the different errors? Apparently you have to be a registered WinZip user
to install the command-line add-on and I am not about to pay to register
it just to find out what the errorlevels are.
I'm a registered user,
but the help doesn' say much about errorlevel meanings

<cite>
*Using return codes (errorlevels)*

WZZIP and WZUNZIP will in most cases return a nonzero errorlevel in the
event of a serious error; otherwise, an errorlevel of 0 is returned.
You can use these return codes in batch files and other automated
processing. For example:

wzzip filename.zip *.doc
If Not ErrorLevel 1 Goto Exit
Echo ***SERIOUS ERROR DETECTED***
:Exit
</cite>
Post by Norman L. DeForest
Errorlevels returned can be 0 to 255 (or be undefined if a program uses
the old terminate function instead of the advanced terminate function).
COMMAND.COM's "If ErrorLevel n" (where 'n' is a number from 0 to 255) can
be translated as "If ErrorLevel is greater than or equal to n".
Obviously, "If ErrorLevel 0" is always true.
To check for different errorlevels, check the higher numbers first.
You can test all of the possible errorlevels returned by a specific run of
wzzip.exe -^ -P -r -whs c:\changes.zip c:\projects -td1
if errorlevel 255 goto e255
if errorlevel 254 goto e254
... etc. etc.
if errorlevel 1 goto e1
echo errorlevel 0 (no error)
goto done
:e255
echo errorlevel 255
goto done
<snip>
Another approach with only one changing line is:

@echo off
if %1. == err. goto DispErr
wzzip.exe -^ -P -r -whs c:\changes.zip c:\projects -td1
if errorlevel 255 call %0 err 255
if errorlevel 254 call %0 err 254
...
if errorlevel 1 call %0 err 1
goto :end
:DispErr
echo Errorlevel is %2
:end

And since I'm a lazy bone I'd create the lines with a small
qbasic program:

OPEN "IfErr.txt" FOR OUTPUT AS #1
FOR i = 255 TO 1 STEP -1
PRINT #1, "if errorlevel "; i; " call %0 err "; i
NEXT i


HTH
--
Gruesse Greetings Saludos Saluti Salutations
Matthias
---------+---------+---------+---------+---------+---------+---------+
Loading...