从命令行应用程序将字符串值传递给Inno Setup

Dav*_*vy8 2 inno-setup return-value

方案是我们有一个客户端/服务器应用程序,客户端安装是使用Inno Setup的引导程序,从IP /端口号指定的服务器下载客户端.我们希望能够通过UDP广播检测本地网络上是否有服务器,并且可以编写一个控制台应用程序来执行此操作.问题是,我们如何将信息从控制台应用程序传递给安装程序?

我可以捕获返回代码,但这只能是一个int.据我所知,在Inno Setup中读取文件的唯一功能是在预处理器中,因此我们无法读取控制台应用程序在运行时创建的文件.我唯一能想到的是返回一个int,其中前4位是'.的位置和:在端口之前,然后解析出值,这似乎是hackish,flimsy和容易出错,特别是考虑到我对构造字符串的Inno Setup语法/函数并不熟悉.

有什么建议?

小智 5

如果要从Inno Setup中的代码解析命令行参数,请使用与此类似的方法.只需从命令行调用安装程序,如下所示:

c:\MyInstallDirectory>MyInnoSetup.exe -myParam parameterValue
Run Code Online (Sandbox Code Playgroud)

然后你可以在GetCommandLineParam任何需要的地方打电话给这样的:

myVariable := GetCommandLineParam('-myParam');
Run Code Online (Sandbox Code Playgroud)
{ ================================================================== }
{ Allows for standard command line parsing assuming a key/value organization }

function GetCommandlineParam (inParam: String):String; 
var 
  LoopVar : Integer; 
  BreakLoop : Boolean; 
begin 
  { Init the variable to known values } 
  LoopVar :=0; 
  Result := ''; 
  BreakLoop := False; 

  { Loop through the passed in array to find the parameter } 
  while ( (LoopVar < ParamCount) and 
      (not BreakLoop) ) do 
  begin 
    { Determine if the looked for parameter is the next value } 
    if ( (ParamStr(LoopVar) = inParam) and 
       ( (LoopVar+1) < ParamCount )) then 
    begin 
      { Set the return result equal to the next command line parameter } 
      Result := ParamStr(LoopVar+1); 

      { Break the loop } 
      BreakLoop := True; 
    end 

    { Increment the loop variable } 
    LoopVar := LoopVar + 1; 
  end; 
end; 
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助...