Archive: Reading Batch Exit Codes


Reading Batch Exit Codes
Hello all,

I was having some problems with processes plugins and Vista so I decided I would write my own batch script to see if a a process is running. The batch script works fine and returns a different error level / exit code (by EXIT /B ###) depending on whether the process is found or not. All the NSIS documentation and google searches I have seen say ExecWait should be able to read the exit code. But it either always reads 0 or an empty variable. Does anybody have any ideas? I don't really want to use a plugin if I don't have to but if I do, anybody know a good one that will work with XP and Vista?


Just a comment about "I don't really want to use a plugin if I don't have to but if I do", NSIS is really suffering from lack of documentation and maintenance, and a lot of interesting stuff (means up-to-date and the ones to use) are now developped in plugins...

As for your problem, I am using nsExec:

Return Value
------------
If nsExec is unable to execute the process, it will return "error"
on the top of the stack, if the process timed out it will return
"timeout", else it will return the return code from the
executed process.
Read more here: http://nsis.sourceforge.net/Docs/nsExec/nsExec.txt

Gal'

I really didn't want to make it seem that I was anti-plugins, I have just had some problems with some of them and Vista and wanted to try to avoid having more. If there is a plugin out there that will work for me with a minimal chance of problems I will be happy to use it.

Thanks for the suggestion about nsExec, but sadly it didn't work for me. It always returns 0 for me. Any other ideas?


Execute the command line application (command.com on 9x and cmd.exe on NT, or just %COMSPEC% on all) and tell it to execute your batch file. It should return the correct value.

ReadEnvStr $0 COMSPEC
ExecWait '"$0" /c blah.bat' $0

Unfortunately, kichik, your ReadEnvStr didn't work for me either, it always read 1 so it was at least a new result.


Don't use /B as you want it to exit CMD.EXE and set its return value and not the batch's.


Nice suggestion kichik, I removed the /B and then I could read the exit code (just with ExecWait) on Windows XP. However it still gives me problems in Vista. Anyone have ideas that will make Vista happy?