Post by YTHi,
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