Archive: Question about nsExec::ExecToStack and Return Codes


Question about nsExec::ExecToStack and Return Codes
I'm using nsExec::ExecToStack to execute a batch script. The batch script returns an ERRORLEVEL of 1. However, ExecToStack puts a "0" on the stack.

Here's how to reproduce this:

1. Unzip ExecToStack-question.zip.

2. In a Command Prompt window, change into the ExecToStack-question directory created when you unzipped the file.

3. Within the Command Prompt window, run foo.bat and then examine the ERRORLEVEL using echo %ERRORLEVEL%. This demonstrates that foo.bat does, indeed, set ERRORLEVEL to "1".

4. Build and execute the example installer.

From the installation details, you can see that ExecToStack placed a "0" on the stack for the Return Code.

Note that I'm assuming that "Return Code" and "ERRORLEVEL" are synonymous terms. If this is not the case, please correct me.

Any ideas why ExecToStack is not reporting the "1" that gets reported when executing foo.bat from the command-line?

Thanks!


exit /? (exit [/B] [exitCode]) says for exitCode: "If quitting CMD.EXE, sets the process exit code with that number."

I'm not sure if this applies though.

-Stu


I tried both with and without the /b in the batch file.

Based on what I'm observing, it appears that the /b switch makes the error level local to the batch file, but by omitting the /b, makes the error level global to cmd.exe.

nsExec seems to be reporting the exit code of cmd.exe (not of the batch file), which is why it shows exit code 0 with the /b switch, but shows exit code 1 when the /b switch is omitted.

(Hopefully, this makes sense.)


Also good idea is to test it all on Win9x both for exit codes and hidden 'winoldapp's still running.