[All]
Using command line utilties and checking the resultant exit code
Abstract: Using command line utilties and checking the resultant exit code
Problem:
When using the InterBase utilities in a batch file the exit status of the
InterBase utilities needs to be
checked.
Solution:
When writing a batch script on NT or Win95 there is a batch construct to handle checking of exit
status codes.
To check the status code use the construct:
if errorlevel x
where x is the errorlevel you want to check for. This statement will return
true if the exit code is greater than or equal to the number specified. If the
errorlevel is >= to the specified number the specified command will be
executed. This command can include printing of error messages or
exiting the batch file.
Here is an example script to perform a gbak and print an error message
if gbak was unsuccessful:
@echo off
echo "file to gbak is: "
gbak -z -b %1 %2
if errorlevel 1 echo "errorlevel 1"
------------------------------- end script -----------------------------------
The @echo off prevents all commands from being echoed to the screen,
%1 and %2 are the first 2 command line parameters. In this case they
represent the database to be backed up and the filename to backup to.
The if statement after the gbak will check to see if the exit code is >= 1 and
if it is, print an error message.
An exit code of 0 means success and an exit code of 1 means failure, as
defined in common.h.