2016-08-05 101 views
1

我在使用NSIS安裝程序中的某些參數運行批處理文件時遇到問題。在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」「$ I NSTDIR \ Param4「」$ INSTDIR \ Param5「'

我使用.cmd代替.bat。我引用了ExecWait的參數。

我面對的是它打開命令提示符,什麼都不做。命令提示符未採用批處理文件,也不執行批處理文件。

有人能指出我失蹤的是什麼。

回答

1

使用%COMSPEC%時,必須在參數前加上/ C來告訴cmd.exe您要執行命令行的其餘部分。這隻有一半的故事,因爲cmd.exe有愚蠢的報價處理,你必須禁用if 1==1黑客:

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