即使选项存在,NSIS GetOptions 也会抛出错误

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

我正在尝试 运行 NSIS 生成的测试安装程序 (.exe),同时提供命令行参数。我正在使用 GetParameters and GetOptions.

我的代码:

FileOpen [=10=] "$InstDir\output.txt" w

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

FileClose [=10=]

和运行宁此时使用的命令:

installer.exe -pss

我一直在文本文件中得到 Fail,但该选项在命令行字符串中。我做错了什么?

我试过使用 /pss 而不是 -pss,但仍然出现错误。我也有 运行 相同的代码,但有一些修改:

FileOpen [=11=] "$InstDir\output.txt" w

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

FileClose [=11=]

使用命令 installer.exe -pss=true 并且 true 被写入文件,这意味着 $R1 正在接收一个值,但我仍然收到错误。

这里最重要的是我不需要任何实际值,而只需要查看 -pss 选项是否可用。

谁能告诉我我做错了什么或者我的误解在哪里?

第一个IfErrors参数是如果设置了错误标志并且您正在使用0则跳转的地方,这意味着没有跳转所以您的代码有点混乱。

我建议你不要像这样使用相对跳转,使用标签或者更好,使用 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