简体   繁体   中英

Executing Batch File in NSIS installer

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 suppose this is obvious, otherwise the batch file wouldn't exist yet).

I tried to use MUI_PAGE_CUSTOMFUNCTION_PRE with the finish page in order to run it but when it gets to that portion of the script it appears that it skips right over it. Below is how I invoke it.

;;Finish Page
!define MUI_PAGE_CUSTOMFUNCTION_PRE Done
!insertmacro MUI_PAGE_FINISH

Function Done
    ExecWait '"$INSTDIR\BatchFile" "$INSTDIR" "$DATA_FOLDER"'
FunctionEnd

Thanks in advance for your help.

UPDATE

I have now tried using the following:

ExpandEnvStrings $0 %COMSPEC% 
ExecWait '"$0" /C "$INSTDIR\batch.bat" "$INSTDIR" "$DATA_FOLDER"'

This did not work, so I took out the /C to see what the cmd prompt was saying (it is popping up, but closing immediately) and it seems as though it executes cmd.exe but that's it, it doesn't complete the rest of the execute.

UPDATE #2

The core knowledge that led to me getting it to work can be found here:

Windows batch files: .bat vs .cmd?

For whatever reason .bat files do not agree with ExecWait.

In the end:

ExecWait '"$INSTDIR\BatchFile.cmd" "$INSTDIR" "$DATA_FOLDER"'

Worked just fine.

Exec[Wait] needs proper quoting:

ExpandEnvStrings $0 %COMSPEC%
ExecWait '"$0" /C "c:\path\to\batch.cmd" "quoted param" normalparam "c:\last param"'

I have done this using an exec extension very successfully

This is the syntax:

  SetOutPath $INSTDIR\${APPLICATION_DIR}
    ExpandEnvStrings $0 %COMSPEC%
    nsExec::ExecToStack '"C:\path-tobatch-file\commands.bat"'

Here is a link to the NSIS Wiki http://nsis.sourceforge.net/Docs/nsExec/nsExec.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM