Reputation: 9544
I am trying to factor out a snippit of code I have ALL OVER my NSIS installer. The snippet is as follows:
nsExec::ExecToStack 'Dism.exe /Online /Enable-Feature /FeatureName:NetFx3'
Pop $0
${If} $0 != 0
Pop $0
Push ".NET 3.5 failed to install: $\n$0"
Call DetailPrintTS
StrCpy $Errors "$Errors Errors From .NET 3.5 install:$\n$0$\n$\n"
${EndIf}
So I'd like to factor this to something like:
Function LoggedExec
Pop $0
Pop $1
nsExec::ExecToStack $0
Pop $0
${If} $0 != 0
Pop $0
Push "$1 failed to install: $\n$0"
Call DetailPrintTS
StrCpy $Errors "$Errors Errors From $1 install:$\n$0$\n$\n"
${EndIf}
FunctionEnd
and then call it as follows:
Push 'Dism.exe /Online /Enable-Feature /FeatureName:NetFx3'
Push '.NET 3.5'
Call LoggedExec
Note that DetailPrintTS is another function I made that includes a timestamp in DetailPrint:
Function DetailPrintTS
Pop $7
${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6
DetailPrint "$4:$5:$6 -- $7$\n"
FunctionEnd
Upvotes: 0
Views: 824
Reputation: 11465
Remember that Push
/ Pop
are acting on a stack (in other words, a lifo: last in, first out).
From your snippet, you seem to Pop
the arguments in LoggedExec
in the same order that they were Push
ed. Instead, if you Push
the command and after the text for the log, you need to Pop
in reversed order:
Push 'Dism.exe /Online /Enable-Feature /FeatureName:NetFx3'
Push '.NET 3.5'
Call LoggedExec
;in LoggedExec
pop $1
pop $0
Upvotes: 1