Install4J:stderr 和 return 代码重定向到变量只写入一次

Install4J: stderr and return code redirection into variable gets written only once

我正在使用 Install4j 6.1.6,并且正在尝试执行以下操作:

我想 运行 使用来自安装程序(第一个屏幕)的参数从外部生成一个 jar 文件,然后在第二个屏幕上显示结果。


所以,第一个屏幕有:

  1. 一些输入字段
  2. 一个"Run executable or batch file"动作
    • 可执行文件:${installer:sys.javaHome}\bin\java
    • 来自先前输入字段的参数放在一起
    • "Wait for termination"勾选
    • "Variable name for return code" 是 my-returncode
    • "Redirect stderr" 到安装程序变量 my-stderr
  3. 和一个 "Run script" 自动进入下一屏幕的动作
    • context.gotoScreen(context.getScreenById("nextScreenId")); return 真;

第二个屏幕根据 my-returncodemy-stderr 的值显示适当的标签。

每个案例都运行良好。

但是,我决定将第二个屏幕上的 "Back button" 更改为始终可见 因为这样用户可以解决问题(如果他输入错误在输入字段中)。

所以我在第一个屏幕上的 "Run executable or batch file" 操作上检查了 "Can be executed multiple times"。


现在,当我在输入字段中输入错误数据时,单击 Next > 脚本将 运行 失败,第二个屏幕会显示有错误。 my-returncodemy-stderr 包含退出代码和错误消息。

然后我单击 < Back 按钮并修复问题,我单击 Next > 然后脚本 运行 这次成功了,但我仍然遇到以前的错误,因为 my-returncodemy-stderr 没有更新,它们仍然包含最后的错误消息和退出代码!

在这种情况下,我该如何解决这个问题并让 Install4J 更新变量?


更新:

我意识到第二个动作(进入下一个屏幕)完全没有必要,所以我删除了它。

这仍然没有解决我的问题,这里是.install4j/installation.txt的相关部分:

[INFO] com.install4j.runtime.beans.screens.FormScreen [ID 1199]: Show screen
       Variable changed: shouldLaunchExternalScript=true[class java.lang.String]
       Variable changed: externalScriptDataFolder=F:\badfolderpath[class java.lang.String]

这是用户可以 select 启动此外部脚本并设置数据文件夹的屏幕。我单击了 "launch script" 单选按钮并设置了错误的文件夹路径。

[INFO] com.install4j.runtime.beans.actions.misc.RunExecutableAction [ID 1367]: Execute action
       Property arguments: [-cp, ./*, -Ddata.dir=F:\badfolderpath, ...]
       Property rollbackSupported: false
       Property returnCodeVariable: my-returncode
       Property stdoutRedirectionMode: No redirection
       Property stdoutVariableName: 
       Property workingDirectory: ...
       Property failOnStderrFileError: false
       Property failOnStdinFileError: false
       Property failOnStdoutFileError: false
       Property rollbackExecutable: null
       Property rollbackArguments: null
       Property rollbackWorkingDirectory: null
       Property stderrRedirectionMode: To installer variable
       Property stderrVariableName: my-stderr
       Property stdinRedirectionMode: No redirection
       Property environmentVariables: {}
       Property keepConsoleWindow: true
       Property showWindowsConsole: false
       Property useRollbackExecutable: false
       Property includeParentEnvironmentVariables: true
       Property stdinString: 
       Property timeout: 0
       Property stdinFile: null
       Property stderrFile: null
       Property stdoutFile: null
       Property wait: true
       Property waitForStreams: true
       Property executable: c:\users\user\appdata\local\temp\e4jb23d.tmp_dir1564671223\jre\bin\java
       Property logArguments: true
       used working dir: ...
       execute using batch file

脚本使用给定参数启动,但会失败:

[ERROR] com.install4j.runtime.beans.actions.misc.RunExecutableAction [ID 1367]: return value is 1
[INFO] com.install4j.runtime.beans.actions.misc.RunExecutableAction [ID 1367]: Variable changed: my-stderr
       Variable changed: my-returncode=1[class java.lang.Integer]
[ERROR] com.install4j.runtime.beans.actions.misc.RunExecutableAction [ID 1367]: return value is 1
        Execute action not successful after 19696 ms
[INFO] com.install4j.runtime.beans.screens.FormScreen [ID 1199]: command: move 1 screens, executing actions, checking condition
[INFO] com.install4j.runtime.beans.screens.FormScreen [ID 1360]: Show screen

Return代码1表示失败,0表示外部脚本成功。变量已更新,现在我在第二个屏幕上看到外部脚本失败。我现在单击返回并解决问题(select 正确的文件夹路径):

[INFO] com.install4j.runtime.beans.screens.FormScreen [ID 1360]: command: go back 1 screens using history
[INFO] com.install4j.runtime.beans.screens.FormScreen [ID 1199]: Show screen
       Variable changed: shouldLaunchExternalScript=true[class java.lang.String]
       Variable changed: externalScriptDataFolder=F:\goodfolderpath[class java.lang.String]

变量已更新并使用正确的参数再次启动外部脚本:

[INFO] com.install4j.runtime.beans.actions.misc.RunExecutableAction: Execute action
       Property arguments: [-cp, ./*, -Ddata.dir=F:\goodfolderpath, ...]
       Property rollbackSupported: false
       Property includeParentEnvironmentVariables: true
       Property stderrFile: null
       Property executable: c:\users\user\appdata\local\temp\e4jb23d.tmp_dir1564671223\jre\bin\java
       Property stdinString: 
       Property wait: true
       Property stdinFile: null
       Property stdoutFile: null
       Property waitForStreams: true
       Property logArguments: true
       Property timeout: 0
       Property stderrVariableName: my-stderr
       Property stdinRedirectionMode: No redirection
       Property rollbackArguments: null
       Property stdoutRedirectionMode: No redirection
       Property rollbackWorkingDirectory: null
       Property workingDirectory: ...
       Property stdoutVariableName: 
       Property environmentVariables: {}
       Property returnCodeVariable: my-returncode
       Property rollbackExecutable: null
       Property stderrRedirectionMode: To installer variable
       Property useRollbackExecutable: false
       Property failOnStdinFileError: false
       Property failOnStdoutFileError: false
       Property failOnStderrFileError: false
       Property showWindowsConsole: false
       Property keepConsoleWindow: true
       used working dir: ...
       execute using batch file
       Variable changed: my-stderr
       Variable changed: my-returncode=0[class java.lang.Integer]
       Execute action successful after 16416 ms

脚本运行成功,变量已更改(我的-return代码是1,现在是0)。

[INFO] com.install4j.runtime.beans.screens.FormScreen [ID 1199]: command: move 1 screens, executing actions, checking condition
[INFO] com.install4j.runtime.beans.screens.FormScreen [ID 1360]: Show screen

但是,在结果屏幕上,我仍然看到未更新的、以前的 my-stderr 和 my-returncode 值,表明 运行 外部脚本存在错误。

我可以通过将此行添加到第二个屏幕的预激活脚本来解决问题:

formEnvironment.reinitializeFormComponents();