#10 – The Return Value from Main() Sets ERRORLEVEL Variable in Windows
June 27, 2010 4 Comments
If your Main() function returns an integer value, you can check that value in the calling program or script using the ERRORLEVEL environment variable. By convention, a return value of 0 indicates success and any other value indicates an error. Below is a sample .bat file that calls a program called MyProgram and then checks the return value.
@echo off
MyProgram
IF "%ERRORLEVEL%" == "0" goto OK
:NotGood
echo Bad news. Program returned %ERRORLEVEL%
goto End
:OK
echo Everything A-OK
:End
i didnt get it…how it works… ???
The ERRORLEVEL environment variable is automatically set by Windows to contain the return value of your program. In the example above, if your program returned a value of -1, the script would echo “Bad news. Program returned -1″. If your program returned 0, the script would echo “Everything A-OK”.
ya i understood the code and but practically how to implement it to get that echo sound ?
Echo will echo out to the console any string that you give it. It’s a DOS command. You can experiment with it in a command prompt.