【问题标题】:Issues in executing a Batch file in NSIS installer在 NSIS 安装程序中执行批处理文件的问题
【发布时间】:2016-12-12 03:42:40
【问题描述】:

我在运行带有 NSIS 安装程序中某些参数的批处理文件时遇到问题。

我已按照中提到的说明进行操作 Executing Batch File in NSIS installer

我使用的命令是

SetOutPath "$INSTDIR\64-bitRegistration"

ExpandEnvStrings $0 %COMSPEC%

ExecWait '"$0" "$INSTDIR\64-bitRegistration\EIQServersRegistration.cmd" "$INSTDIR\Param1" "$INSTDIR\Param2" "$INSTDIR\Param3" "$INSTDIR\Param4" "$INSTDIR\Param5" '

我使用 .cmd 而不是 .bat。我已经引用了 ExecWait 的参数。

我面临的是它打开命令提示符并且什么都不做。命令提示符不获取批处理文件,也不执行批处理文件。

谁能指出我错过了什么。

【问题讨论】:

    标签: nsis


    【解决方案1】:

    使用 %COMSPEC% 时,您必须在参数前添加 /C 以告诉 cmd.exe 您要执行命令行的其余部分。这只是故事的一半,因为 cmd.exe 具有愚蠢的引号处理,您必须使用 if 1==1 hack 禁用:

    Section
    ; Create test batch file:
    InitPluginsDir
    StrCpy $InstDir $PluginsDir
    CreateDirectory "$INSTDIR\64-bitRegistration"
    FileOpen $0 "$INSTDIR\64-bitRegistration\EIQServersRegistration.cmd" w
    FileWrite $0 '@echo off$\n'
    FileWrite $0 'Title Test batch %*$\n'
    FileWrite $0 'dir /S/B %windir%\*shell32*$\n' ; Some long running command
    FileClose $0
    
    ; Run it:
    ExpandEnvStrings $0 %COMSPEC% 
    ExecWait '"$0" /C if 1==1 "$INSTDIR\64-bitRegistration\EIQServersRegistration.cmd" "foo" bar "b a z"'
    
    ; Or let Windows select the batch handler:
    ExecWait '"$INSTDIR\64-bitRegistration\EIQServersRegistration.cmd" "foo" bar "b a z"'
    SectionEnd
    

    【讨论】:

      猜你喜欢
      • 2011-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-29
      相关资源
      最近更新 更多