1.

Solve : Some dos question?

Answer»

I would like to check the script error within the batch file.
And i find this code:
"ESSCMD LOAD.SCR (one of the script statement)
If not %errorlevel%==goto Error

Echo All operations COMPLETED successfully
EXIT

:Error
Echo There was a problem running the script"

I would like to as what is the function of == ?
and Is %errorlevel% just a varable?

if this statement is not correct, can anyone help me ?

Thanks a lot

"==" compares two strings. 'IF/?' for more information.

And yes "%errorlevel%" is a variable that commands alter, regarding how they completed, successfully or not. It is also used for 'choice'.when i try to test the following command, i get some problem.
First: it show that 'W' is not recognized as an internal or external command. operable program or batch file.
Second, if 'W' which is a bat file , it is work.

My question is i just want to check the script command correct or wrong, if correct return 0 to me , otherwise echo 1.

@echo off
LOAD.SCR
If not %errorlevel%==goto W

:W
Echo 1== MEANS "equal to"

errorlevel is not really a variable. It does not have percent signs around it and you cannot set its value, or read it, just compare it to fixed values.

It is used like this

SOME COMMAND
if errorlevel 2 goto label2
if errorlevel 1 goto label1
if errorlevel 0 goto label0
goto message

:label0
some code here
goto end

:label1
some code here
goto end

:label2
:some code here
goto end

:message
echo error code was not 0, 1 or 2

:end




Do errorlevel = 0 mean not error, not equal 0 having error ?Quote from: cityjack on August 16, 2007, 07:59:55 AM

Do errorlevel = 0 mean not error, not equal 0 having error ?

It's not "errorlevel=0" , it's "errorlevel 0".

It can mean that, but not always! It means that the program returned an errorlevel, and the errorlevel was "0". DOS Errorlevel is a return code sent by a terminating program such as batch, exe, com or any applications. ERRORLEVELS are not a standard feature of every command. What the return code means is up to the programmer. However, most (not all) programmers agree that an errorlevel 0 means the command executed successfully, and an errorlevel 1 or higher usually spells trouble. But there may be some exceptions to this general rule.





Discussion

No Comment Found