DOS Batch Script win2003 -Getting  "'else' is not recognized as an internal or external command, "

vickie0918
vickie0918 used Ask the Experts™
on
Problem Statement:  

-->> It appears that an " else clause " is being flagged as not being recognized as an internal or external command.  The " else clause " is used to handle an errorlevel with exit code " 0"; i.e., rc=0 scenario

Here is the specific if-else clause: (more of code follows)

if ERRORLEVEL 1 (
   if ERRORLEVEL 35 goto RAISE35
   if ERRORLEVEL 30 goto RAISE30
   if ERRORLEVEL 25 goto RAISE25
   if ERRORLEVEL 20 goto RAISE20
   if ERRORLEVEL 15 goto RAISE15
   if ERRORLEVEL 10 goto RAISE10
   if ERRORLEVEL 5  goto RAISE5
)
else (
   goto SUCCESS
)

#1: >>> Here is the log file reference:

icrosoft Windows [Version 5.2.3790]
Sun 01/31/2010:14:13:44.64: Checking for ErrorHandling in svr-t-infor-im1,svr-t-infor-im2
Sun 01/31/2010:14:13:44.64: Checking for staging directory
Sun 01/31/2010:14:13:44.64: checking for AppLib_Options.js
01/31/2010  01:53 PM            22,978 AppLib_Options.js
01/26/2010  05:08 PM               541 test_AppLib_Options.js
Sun 01/31/2010:14:13:44.72: found..
Sun 01/31/2010:14:13:44.72: found.. checking for valid AppLib_Options.js
Sun 01/31/2010:14:13:44.72: validating HOST_ENVIRONMENT variable.
Sun 01/31/2010:14:13:44.72: C:\dmupdates\IM-CF\IM\Misc\AppLib_Options.js is the javascript file deployed ...
#define HOST_ENVIRONMENT "TEST"
Sun 01/31/2010:14:13:44.77: valid environment is set to TEST
Sun 01/31/2010:14:13:44.77: validating IM logging level...
//#define DEBUG_ABOVEANDBEYOND 1
Sun 01/31/2010:14:13:44.81: IM Logging is disabled in TEST..
Sun 01/31/2010:14:13:44.81: checking for AboveAndBeyond.mop
01/29/2010  10:27 AM         3,585,570 AboveAndBeyond.mop
Sun 01/31/2010:14:13:44.89: found..
Sun 01/31/2010:14:13:44.89: checking for AboveAndBeyondXML.wpt
10/30/2008  04:29 PM            20,084 AboveAndBeyondXML.wpt
Sun 01/31/2010:14:13:44.97: found..
Sun 01/31/2010:14:13:44.97: New code drop prerequisite check completed successfully.......

Sun 01/31/2010:14:13:44.99: Reached the end o ErrorHandling script

Sun 01/31/2010:14:13:44.99: *** Note: End of ErrorHandleCheck -  completed with RC : 0  ***


Sun 01/31/2010:14:13:45.00:  ****** in CheckErrors with this error:  0

'else' is not recognized as an internal or external command,
operable program or batch file.

Sun 01/31/2010:14:13:45.03: -- Initating IM Deployment -- Please Stand by..previous errorlevel was: 9009

Sun 01/31/2010:14:13:45.03:  ************* Deploying IM  **************



#2>>>> Here is the script snippet:


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 goto RAISE30
   if ERRORLEVEL 25 goto RAISE25
   if ERRORLEVEL 20 goto RAISE20
   if ERRORLEVEL 15 goto RAISE15
   if ERRORLEVEL 10 goto RAISE10
   if ERRORLEVEL 5  goto RAISE5
)
else (
   goto SUCCESS
)

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

:RAISE30
  echo %date%:!time!: FAILURE ALERT *** AboveAndBeyond.mop does not exist. exiting... ***

:RAISE25
 echo %date%:!time!: FAILURE ALERT *** Error: IM Logging is enabled. exiting... ***

:RAISE20
  echo %date%:!time!: FAILURE ALERT *** The HOST_ENVIRONMENT variable check Failed exiting... ***
 
:RAISE15
  echo %date%:!time!: FAILURE ALERT *** AppLib_Options.js does not exist. exiting... ***
 
:RAISE10
  echo %date%:!time!: FAILURE ALERT *** Staging directory does not exist.exiting... ***
 
:RAISE5
  echo %date%:!time!: FAILURE ALERT *** setEnv.bat not found in ErrorHandlingDeploy script. exiting... ***

 goto END


:SUCCESS
  echo.
  echo %date%:!time!: -- Initating IM Deployment -- Please Stand by..previous errorlevel was: !ERRORLEVEL!
  echo.
  echo %date%:!time!:  ************* Deploying IM  **************
  echo.
 
  echo
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Your Problem is right in the part

this is the problem

if ERRORLEVEL 1 (
   if ERRORLEVEL 35 goto RAISE35
   if ERRORLEVEL 30 goto RAISE30
   if ERRORLEVEL 25 goto RAISE25
   if ERRORLEVEL 20 goto RAISE20
   if ERRORLEVEL 15 goto RAISE15
   if ERRORLEVEL 10 goto RAISE10
   if ERRORLEVEL 5  goto RAISE5
)
else (
   goto SUCCESS
)

Change it to this. Remember it must be ) else (

if ERRORLEVEL 1 (
   if ERRORLEVEL 35 goto RAISE35
   if ERRORLEVEL 30 goto RAISE30
   if ERRORLEVEL 25 goto RAISE25
   if ERRORLEVEL 20 goto RAISE20
   if ERRORLEVEL 15 goto RAISE15
   if ERRORLEVEL 10 goto RAISE10
   if ERRORLEVEL 5  goto RAISE5
) else (
   goto SUCCESS
)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial