在 NSIS 安装程序中执行 Bat 文件 - 不工作 [英] Executing Bat File in NSIS installer-not working

查看:32
本文介绍了在 NSIS 安装程序中执行 Bat 文件 - 不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为我的 java 项目成功构建了 nsis 脚本.我有一个批处理文件,我需要在我的 NSIS 安装程序中运行它.它必须在提取所有文件后运行.我尝试了以下命令

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

这个也试过了:

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

我参考了这个链接.

我的要求是:

1.安装完成后如何使用Nsis脚本启动批处理文件?

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

推荐答案

如果您不打算使用结果,为什么要调用 ExpandEnvStrings?路径在您的两个示例中甚至不匹配.

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

您可以根据需要使用几个 exec 插件:nsExec, ExecDosExecCmd

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

这篇关于在 NSIS 安装程序中执行 Bat 文件 - 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆