【问题标题】:Get exit code from batch file in Inno Setup using ShellExecuteEx使用 ShellExecuteEx 从 Inno Setup 中的批处理文件中获取退出代码
【发布时间】:2016-04-29 17:49:57
【问题描述】:

我有几个从 Inno Setup 执行的批处理文件。我使用ShellExecuteEx() 执行批处理文件:

function ShellExecuteWait(const Verb, Filename, Params, WorkingDir: string; const ShowCmd: integer; const Timeout: cardinal; var ExitCode: DWORD): boolean;
var
  ExecInfo: TShellExecuteInfo;
begin
  Result := false;

  ExecInfo.cbSize := SizeOf(ExecInfo);
  ExecInfo.fMask := SEE_MASK_NOCLOSEPROCESS;
  ExecInfo.Wnd := 0;
  ExecInfo.lpVerb := Verb;
  ExecInfo.lpFile := Filename;
  ExecInfo.lpParameters := Params;
  ExecInfo.lpDirectory := WorkingDir;
  ExecInfo.nShow := ShowCmd;

  if ShellExecuteEx(ExecInfo) then
  begin
    if WaitForSingleObject(ExecInfo.hProcess, Timeout) = WAIT_TIMEOUT then
    begin
      TerminateProcess(ExecInfo.hProcess, WAIT_TIMEOUT);
    end else begin
    end;
    GetExitCodeProcess(ExecInfo.hProcess, ExitCode);
    Result := (ExitCode = ERROR_SUCCESS);
  end else begin
    ExitCode := GetLastError();
  end;
end;

if (not ShellExecuteWait('', 
                         Command,
                         Params,
                         ExpandConstant('{tmp}'), 
                         SW_SHOW, 
                         Timeout,
                         ResultCode)) then...

但是无论我尝试什么,我都无法从ResultCode中的批处理文件中获取退出代码(我总是返回0)。

在研究这个问题时,我读到批处理不能使用exit /b NN。所以我删除了/b 开关,但我仍然得到0。

我必须怎么做才能成功地从批处理文件中获取退出代码?

丹尼斯

【问题讨论】:

  • 您使用ShellExecuteEx而不是普通ShellExec的任何原因?

标签: batch-file inno-setup exit-code shellexecuteex


【解决方案1】:

我发现了问题。调用批处理文件的命令包括通过另一个程序的管道,因此我返回的结果代码实际上来自通过管道传输脚本输出的程序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-23
    • 1970-01-01
    • 1970-01-01
    • 2012-12-25
    • 2011-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多