Executing Bat File in NSIS installer-not working

孤街醉人 提交于 2019-12-11 11:58:35

问题


I have builded nsis script successfully for my java project.I have a batch file that I need to run within my NSIS installer.It must run after all the files have been extracted.I have tried following commands

!define MUI_FINISHPAGE_RUN $INSTDIR\bin\batch.bat

This one also have tried:

SetOutPath $INSTDIR
ExpandEnvStrings $0 %COMSPEC%
nsExec::ExecToStack '"$INSTDIR\batch.bat"'

I have referred this link.

My Requirement is:

1.How to start batch file after installation completion using Nsis script?


回答1:


Why call ExpandEnvStrings if you are not going to use the result? The path does not even match in your two examples.

As long as you get the path and quotes correct it should work:

!include MUI2.nsh
!insertmacro MUI_PAGE_INSTFILES
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_FUNCTION RunBatch
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE English

Function RunBatch
;The most basic version, runs with visible console:
ExecWait '"$temp\test.cmd" /foo "bar baz" /blergh'

;You must use cmd.exe if you want redirection (With stupid extra quotes for cmd.exe):
ExpandEnvStrings $0 %COMSPEC%
ExecWait '"$0" /C ""$temp\test.cmd" /foo "bar baz" /blergh > "$temp\stdout.txt""'

;Use one of the exec plugins if you want to hide the console:
nsExec::Exec '"$temp\test.cmd" /foo "bar baz" /blergh'
FunctionEnd

There are several exec plugins you can use depending on your needs: nsExec, ExecDos or ExecCmd



来源:https://stackoverflow.com/questions/12934788/executing-bat-file-in-nsis-installer-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!