errorlevel works on one server but not other

478 views Asked by At

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 ?

1

There are 1 answers

0
LS_ᴅᴇᴠ On

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.