0

I have two Windows 2008 SP2 servers, one dev other production. Production has Microsoft CLuster services running. Now in one particular batch script following commands are there:

dsmc incr "%ARCHIVE_DIR%\*"
if errorlevel 1 goto EXCPT
more code to do purging

Excpt:
echo "script backup error"

In dev this works as expected, dsmc incr returns 8 on successful completion and script moves to purging code. However in production even though dsmc incr return 8, the errorlevel always evaluates to 1 and it jumps to Excpt: . Can anyone help on this please ?

Nishant Bhardwaj
  • 638
  • 1
  • 6
  • 13
  • I have an update, the dsmc incr returns 0 on dev and return code 8 in production. so it makes sense as per [link](http://stackoverflow.com/questions/3942265/errorlevel-in-a-for-loop-batch-windows) if errorlevel 1 mean that errorlevel is greater than or equal to 1 not just one. – Nishant Bhardwaj Aug 29 '13 at 21:15
  • Correct it in your question! – LS_ᴅᴇᴠ Aug 30 '13 at 07:58

1 Answers1

1

Check IF help!

 `IF /?`

You will find:

ERRORLEVEL (...) Specifies a true condition if the last program run returned an exit code equal to or greater than the number specified.

So,

if errorlevel 1 ...

will evaluate true for any errorlevel>=1.

To get exact matching, use:

IF ERRORLEVEL 1 IF NOT ERRORLEVEL 2 ...

or

IF %ERRORLEVEL% == 1 ...

Last one will not work on environments where ERRORLEVEL is used as environment variable.

LS_ᴅᴇᴠ
  • 10,823
  • 1
  • 23
  • 46