简体   繁体   English

在NSIS安装程序中执行批处理文件

[英]Executing Batch File in NSIS installer

I have a batch file that I need to run within my NSIS installer. 我有一个批处理文件,我需要在我的NSIS安装程序中运行。 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. 我尝试将MUI_PAGE_CUSTOMFUNCTION_PRE与完成页面一起使用以运行它,但是当它到达脚本的那一部分时,它似乎跳过它。 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 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. 这不起作用,所以我拿出/ C看看cmd提示符说的是什么(它弹出,但立即关闭)似乎它执行cmd.exe但是就是这样,它没有完成其余的执行。

UPDATE #2 更新#2

The core knowledge that led to me getting it to work can be found here: 可以在这里找到导致我使用它的核心知识:

Windows batch files: .bat vs .cmd? Windows批处理文件:.bat vs .cmd?

For whatever reason .bat files do not agree with ExecWait. 无论出于何种原因.bat文件都不同意ExecWait。

In the end: 到底:

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

Worked just fine. 工作得很好。

Exec[Wait] needs proper quoting: Exec [等待]需要正确引用:

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 我已经非常成功地使用了exec扩展

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 这是NSIS Wiki的链接http://nsis.sourceforge.net/Docs/nsExec/nsExec.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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