Archive: Can't understand how stack works


Can't understand how stack works
I've written following function:

Function KillMyProcess
; Change current directory to temp
; to prevent creation of TempWmicBatchFile.bat
Push $OUTDIR
StrCpy $OUTDIR $TEMP
nsexec::ExecToLog "wmic process where name='MyApp.exe' delete"
Pop $OUTDIR
FunctionEnd


As far as I know $OUTDIR should not change after this function is called, but it equals to 0 instead. I tried to add debug message boxes. Looks like everything goes fine until Pop is called which just sets $OUTDIR value to zero. Why is that?

And also I've discovered that changing $OUTDIR on a page before instfiles does not help. Looks like it do not change current directory before instfiles.


From the documentation for the nsExec plugin:

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.
So your code is putting the return value from nsExec into $OUTDIR and leaving the original value still on the stack. You need to use another Pop command to retrieve the $OUTDIR value you saved on the stack.

There is a wiki page that has some information about how the stack works:
http://nsis.sourceforge.net/Pop,_Pus...h..._The_Stack

Thank you