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

查看:92
本文介绍了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 + '\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}(和其他常量)可能包含空格.

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天全站免登陆