Archive: execwait problems


execwait problems
Hello everyone!
A bit of a problem appeared when using ExecWait

Here's a piece of my NSIS script:

ClearErrors
ExecWait '"$INSTDIR\returnZero.exe"'
IfErrors 0 errors
Goto done
errors:
MessageBox MB_OK "Errors!"
Abort
done:


returnZero is a dummy, a program written in C++ that just can't be more simple:

int main(int argc, char* argv[])
{
exit(0);
}

But the installer goes to errors label anyway, as if the return code of my program was not 0.

Could anybody please help me with this prob?


The error flag will only be raised if that executable could not be run (e.g. file not found). This is not related to the exit code at all. To capture the exit code, you must use another variable. Like this:

ClearErrors
ExecWait '"$INSTDIR\returnZero.exe"' $0
IfErrors errors
StrCmp $0 0 done nonezeroexitcode

errors:
MessageBox MB_OK "Faild to run executable!"
Abort

nonezeroexitcode:
MessageBox MB_OK "Executable returned exit code != 0"
Abort

done:


Also I think you used "IfErrors" wrongly!

Your code says: IF errors THEN nothing ELSE goto label "errors"
But it should be: IF errors THEN goto label "errors" (ELSE nothing)

Ow, thank you alot. It started working :) (By the way, the problem also was I messed up $INSTDIR and $EXEDIR)

The error flag will only be raised if that executable could not be run (e.g. file not found). This is not related to the exit code at all
Hm, I'm a bit condused by this - according to ExecWait description,
4.9.1.4 ExecWait
command [user_var(exit code)]
Execute the specified program and wait for the executed process to quit. See Exec for more information. If no output variable is specified ExecWait sets the error flag if the program executed returns a nonzero error code, or if there is an error. If an output variable is specified, ExecWait sets the variable with the exit code (and only sets the error flag if an error occurs; if an error occurs the contents of the user variable are undefined).

You are right. If you omit the variable, then ExecWait will indeed raise the error flag for a none-zero exit code. But then you cannot distinguish between an error (process could not be started) and a none-zero exit code (process did run, but returned a value != zero). It's your decision what you need. But make sure you use IfErrors correctly: The installer will jump to the first label when there was an error and it will jump to the second label when there was NO error. The second label can be omitted, if not needed. See my code above ...