Inno Setup 中的输出重定向如何工作? [英] How does output redirection work in Inno Setup?

查看:19
本文介绍了Inno Setup 中的输出重定向如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里看到了这个问题:如何在 Inno Setup 中获取已执行程序的输出?

I saw this question here: How to get an output of an Exec'ed program in Inno Setup?

但我自己无法让它工作,注释掉的代码是我尝试使其工作,但我求助于 bat 文件,因为我无法使我的重定向工作.CacheInstanceNameCacheInstanceDir 是在别处定义的全局变量:

But I can't get it to work myself, the commented out code are my attempts to make this work, but I resorted to a bat file because I couldn't make my redirection work. CacheInstanceName and CacheInstanceDir are global variable defined elsewhere:

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 + 'inccontrol.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 > 调用命令.输出文件.不要忘记在适当的地方包含引号,因为 {tmp}(和其他常量)可能包含空格.

The output redirection syntax is a feature of the command prompt, not the core Windows APIs. Therefore if you want to redirect output then you need to invoke the command via {cmd} /c actual-command-line > output-file. Don't forget to include quotes where appropriate, as {tmp} (and other constants) may contain spaces.

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

However, you should strongly consider rewriting whatever is in that batch file into actual code. Anything you can do in a batch file you can do either directly in the Inno script or in a DLL that you call from the script. And this permits you greater control over error checking and the format of whatever data you want to retrieve.

这篇关于Inno Setup 中的输出重定向如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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