Frank Palmasani
Frank Palmasani

Reputation: 185

NSIS GetOptions is throwing an error even though the option is present

I'm am trying to run a test installer (.exe) generated by NSIS while providing command line arguments. I'm using GetParameters and GetOptions.

My code:

FileOpen $0 "$InstDir\output.txt" w

${GetParameters} $R1
${GetOptions} $R1 "-pss" $R2
IfErrors 0 +3
  FileWrite $0 "Success"
  Goto done
  FileWrite $0 "Fail"
done:

FileClose $0

and the command used when running this:

installer.exe -pss

I keep getting Fail in the text file, but the option is in the command line string. What am I doing wrong?

I've tried using /pss instead of -pss and that still gives me an error. I have also ran the same code with a few revisions:

FileOpen $0 "$InstDir\output.txt" w

${GetParameters} $R1
${GetOptions} $R1 "-pss=" $R2 ;;revision
IfErrors 0 +3
  FileWrite $0 "Success = $R2" ;;revision
  Goto done
  FileWrite $0 "Fail = $R2" ;;revision
done:

FileClose $0

with the command installer.exe -pss=true used and the true is written to the file which means $R1 is recieving a value but I'm still getting an error.

The big thing here is that I don't need any actual value, but instead just need to see if the -pss option is available.

Can anyone tell me what I am doing wrong or where my misunderstanding is?

Upvotes: 2

Views: 1022

Answers (1)

Anders
Anders

Reputation: 101569

The first IfErrors parameter is the place to jump if the error flag is set and you are using 0 and that means no jump so your code is a bit confusing.

I would recommend that you don't use relative jumps like this, use a label or even better, use the LogicLib:

!include FileFunc.nsh
!include LogicLib.nsh

Section

${GetParameters} $R1
${GetOptions} $R1 "-pss" $R2
${IfNot} ${Errors}
    DetailPrint "-pss switch found"
${Else}
    DetailPrint "-pss switch NOT found"
${EndIf}

SectionEnd

Upvotes: 4

Related Questions