我在这里看到了这个问题:How to get an output of an Exec'ed program in Inno Setup?

但是我无法自己使用它,注释掉的代码是我进行这项工作的尝试,但是我求助于bat文件,因为我无法使重定向工作。 CacheInstanceNameCacheInstanceDir是在其他位置定义的全局变量:

function CheckCacheExists(): Integer;
var
  args: String;
  buffer: String;
  ResultCode: Integer;
begin
  // args := 'qlist ' + CacheInstanceName + ExpandConstant(' nodisplay > {tmp}\appcheck.txt');
  // MsgBox(args, mbInformation, MB_OK);
  // Exec(CacheInstanceDir + '\bin\ccontrol.exe', 'qlist ' + CacheInstanceName + ExpandConstant(' nodisplay > "{tmp}\appcheck.txt"'), '', SW_SHOW,

  ExtractTemporaryFile('checkup.BAT');
  Exec(ExpandConstant('{tmp}\checkup.BAT'), CacheInstanceDir + ' ' +
    CacheInstanceName + ' ' + ExpandConstant('{tmp}'), '', SW_SHOW,
    ewWaitUntilTerminated, ResultCode);
  LoadStringFromFile(ExpandConstant('{tmp}\appcheck.txt'),buffer);
  if Pos('^', buffer) = 0 then
  begin
    Result := 0
  end
  else
  begin
    Result := 1
  end
end;

我究竟做错了什么?

最佳答案

输出重定向语法是命令提示符的功能,而不是核心Windows API。因此,如果要重定向输出,则需要通过{cmd} /c actual-command-line > output-file调用命令。不要忘记在适当的地方加上引号,因为{tmp}(和其他常量)可能包含空格。

但是,您应该强烈考虑将该批处理文件中的内容重写为实际代码。您可以在批处理文件中执行的任何操作都可以直接在Inno脚本中执行,也可以在从脚本中调用的DLL中执行。这样,您就可以更好地控制错误检查以及要检索的任何数据的格式。

关于installation - Inno Setup中的输出重定向如何工作?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11441938/

10-14 17:49
查看更多