1

Closed

Incorrect Return Value

description

In the Run method implementation in MyCommand.cs you are returning a value of 1 for success. It appears, however, that this return value is used as the return code (ERRORLEVEL) in command scripts, therefore if I write a batch file thus:
stsadm -o mycommand -url http://myurl if errorlevel 0 goto success :failed echo The command failed.
goto finish
:success
echo The command succeeded.
:finish
Then if you return 1 the command will seem to have failed because errorlevel will be 1 even though it has actually succeeded. I appreciate that the return code of a command can be whatever you want it to be, however, if you want to be consistent with the built-in stsadm commands then you should return 0 for success and a non-zero value for failure.
Closed Apr 25, 2008 at 8:17 PM by glapointe
Issue corrected.

comments

glapointe wrote Apr 23, 2008 at 3:30 AM

You're partially right - returning 1 will not result in the batch file going to the error block (some of the built-in commands return 0 and some return 1 - it's very inconsistent). Even the MSDN how to doc used to return 1 but its been since changed to return 0. Basically any value greater than or equal to zero will be interpreted as a success whereas -1 and -2 will be interpreted as either a syntax error (-2) or a general error (-1). I've modified the code to return 0 and added a comment to indicate that users should use the ErrorCodes enum to return error codes. Thanks for the feedback!

wrote Apr 25, 2008 at 8:17 PM

wrote Feb 12, 2013 at 8:24 PM

wrote May 14, 2013 at 2:15 AM