Link to home
Start Free TrialLog in
Avatar of vickie0918
vickie0918Flag for United States of America

asked on

ERRORLEVEL test not working properly MS DOS Batch Script (windows 2003 server)

Problem: DOS Batch script below incorrectly executes the "SUCCESS" label even though results show that the
ERRORLEVEL is returning an exit code of " 20".

Please note I have included both the following:
#1 resulting log file
#2 the script

#1>>>Here is the resulting log file

Microsoft Windows [Version 5.2.3790]
Sun 01/31/2010:12:49:58.01: Checking for ErrorHandling in svr-t-infor-im1,svr-t-infor-im2
Sun 01/31/2010:12:49:58.01: Checking for staging directory
Sun 01/31/2010:12:49:58.01: checking for AppLib_Options.js
01/30/2010  06:26 PM            22,985 AppLib_Options.js
01/26/2010  05:08 PM               541 test_AppLib_Options.js
Sun 01/31/2010:12:49:58.06: found..
Sun 01/31/2010:12:49:58.06: found.. checking for valid AppLib_Options.js
Sun 01/31/2010:12:49:58.06: validating HOST_ENVIRONMENT variable.
Sun 01/31/2010:12:49:58.06: C:\dmupdates\IM-CF\IM\Misc\AppLib_Options.js is the javascript file deployed ...
Sun 01/31/2010:12:49:58.09: Error in AppLib_Options.js: HOST_ENVIRONMENT not TEST and  does not match current environment = TEST

Sun 01/31/2010:12:49:58.10:  ****** in CheckErrors with this error:  20

Sun 01/31/2010:12:49:58.12: FAILURE ALERT *** The HOST_ENVIRONMENT variable check Failed exiting... ***

Sun 01/31/2010:12:49:58.12: THIS IS IN DEPLOY WITH CURRENT ERRORLEVEL EQUAL TO: 20

Sun 01/31/2010:12:49:58.12:  *************should not be here **************

Sun 01/31/2010:12:49:58.13: End of deployment request final ERRORLEVEL returnCode is: 20


#2>>>Here is the script:

@echo off

cls
setlocal enableextensions EnableDelayedExpansion

if  [%1]==[] GOTO DISPLYSYNTX
if  [%2]==[] GOTO DISPLYSYNTX

if exist C:\dmupdates\IM-scripts\Environment_Scripts\setEnv.bat (
  @call C:\dmupdates\IM-scripts\Environment_Scripts\setEnv.bat
) else (
  echo %date%:!time!: setEnv.bat not found. exiting
  exit /b 6
)

set USERID=%1
set PASSWORD=%2

set DMDIR=C:\dmupdates
set ARCDIR=C:\IMArchive


REM ************************ script  begins here.


for /f "tokens=1-4 delims=.: " %%i in ("time /t") do set nowtime=%%i-%%j-%%k-%%l

echo ON

echo %date%:!time!: In Main program with environment  %TARGETHOST%

echo %date%:!time!: *******Call to ErrorHandlingDeploy script with environment**** %TARGETHOST%


if exist C:\dmupdates\IM-SCRIPTS\Deployment_Scripts\ErrorHandlingDeploy.bat (
  @call C:\dmupdates\IM-SCRIPTS\Deployment_Scripts\ErrorHandlingDeploy.bat
  goto CHECKERRORS
) else (
  echo %date%:!time!: ErrorHandlingDeploy.bat not found. exiting
  exit /b 50
)

:CHECKERRORS
echo.
echo %date%:!time!:  ****** in CheckErrors with this error:  !ERRORLEVEL!
echo.

if ERRORLEVEL 1 (
   if ERRORLEVEL 35 goto RAISE35
   if ERRORLEVEL 30 echo %date%:!time!: FAILURE ALERT *** AboveAndBeyond.mop does not exist. exiting... ***
   if ERRORLEVEL 25 echo %date%:!time!: FAILURE ALERT *** Error: IM Logging is enabled. exiting... ***
   if ERRORLEVEL 20 goto RAISE20
   if ERRORLEVEL 15 echo %date%:!time!: FAILURE ALERT *** AppLib_Options.js does not exist. exiting... ***
   if ERRORLEVEL 10 echo %date%:!time!: FAILURE ALERT *** Staging directory does not exist.exiting... ***
   if ERRORLEVEL 5  echo %date%:!time!: FAILURE ALERT *** setEnv.bat not found in ErrorHandlingDeploy script. exiting... ***
)
else (
   goto SUCCESS
)

:RAISE35
  echo %date%:!time!: FAILURE ALERT *** AboveAndBeyondXML.wpt does not exist. exiting... ***

:RAISE20
  echo %date%:!time!: FAILURE ALERT *** The HOST_ENVIRONMENT variable check Failed exiting... ***

:SUCCESS
  echo.
  echo %date%:!time!: THIS IS IN DEPLOY WITH CURRENT ERRORLEVEL EQUAL TO: !ERRORLEVEL!
  echo.
  echo %date%:!time!:  *************should not be here **************
  echo.

:END


echo %date%:!time!: End of deployment request final ERRORLEVEL returnCode is: !ERRORLEVEL!

endlocal

exit /b !ERRORLEVEL!
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vickie0918

ASKER

Really quick response...thank you!
looked at this for over an 1hr and just could not see the answer...have not written DOS batch scripts in 6 years!!  Thanks again!