简体   繁体   English

如何将参数传递给 Inno Setup 命令行编译器?

[英]How do you pass in parameters to the Inno Setup command line compiler?

It was suggested in the IS newsgroup to use /D= but using the iscc.exe that came with version 5.2.3 I get an "Unknown option:" error.在 IS 新闻组中建议使用 /D= 但使用 5.2.3 版本附带的 iscc.exe 我得到一个“未知选项:”错误。

Then in the script, how do you use the value of the command line parameter?那么在脚本中,如何使用命令行参数的值呢?

You do, as MicSim says, need the preprocessor. 正如MicSim所说,你需要预处理器。 It's included in the latest ISPack. 它包含在最新的ISPack中。 Once it's installed, iscc supports /D. 一旦安装,iscc支持/ D.

You can then use the values defined like this (assuming you'd done /DVERSION_NAME=1.23): 然后,您可以使用这样定义的值(假设您已完成/DVERSION_NAME = 1.23):

AppVerName=MyApplication v{#VERSION_NAME}

From the Inno Setup helpfile: 从Inno Setup帮助文件:

Inno Setup Preprocessor replaces the standard Inno Setup Command Line Compiler (ISCC.exe) by an extended version. Inno Setup预处理器用扩展版替换了标准的Inno Setup命令行编译器(ISCC.exe)。 This extended version provides extra parameters to control Inno Setup Preprocessor. 此扩展版本提供了额外的参数来控制Inno Setup预处理器。

The "extra parameters" include the /d option. “额外参数”包括/ d选项。

The point of the answer by @Steven Dunn is to solve the problem with another layer of abstraction: instead of calling iscc your_script.iss directly from the terminal, call your_script.ps1 -YourVar "value" , process the switch, write a #define to the .iss file, and then compile it with iscc . @Steven Dunn的答案是通过另一层抽象来解决问题:不是直接从终端调用iscc your_script.iss ,而是调用your_script.ps1 -YourVar "value" ,处理开关,编写#define.iss文件,然后iscc编译它。 This was not articulated well and I don't think the function shown to parse command line arguments added much value.这没有很好地表达出来,我认为显示的 function 解析命令行 arguments 没有增加多少价值。 However, I'm giving credit where credit is due.但是,我在信用到期时给予信用。

As @jdigital mentioned, ISPP has the /d switch, but ISPP can't be run directly from the terminal (AFAIK).正如@jdigital提到的, ISPP/d开关,但ISPP不能直接从终端运行(AFAIK)。 Hence, something like a secondary scripted approach hinted at by @Steven Dunn is necessary.因此, @Steven Dunn暗示的类似辅助脚本方法的东西是必要的。

You can achieve this by adding placeholders to an existing .iss script and then overwrite them accordingly:您可以通过向现有.iss脚本添加占位符然后相应地覆盖它们来实现此目的:

.iss Template .iss模板

; -- template.iss --

#define MyVar ""

...

.ps1 Script .ps1脚本

#requires -PSEdition Core

# create_iss_script.ps1

param(
    [Parameter(Mandatory=$true)][String]$MyVar,
    [Parameter(Mandatory=$true)][String]$OutFile,
)

$File = '.\template.iss'
$LineToReplace = '#define MyVar ""'
$NewLine = "#define MyVar ""${MyVar}"""

$FileContent = Get-Content -Path $File -Raw

$FileContent.Replace($LineToReplace, $NewLine) | Set-Content -Path $OutFile

Example Terminal Usage终端使用示例

PS> .\create_iss_script.ps1 -MyVar "HelloWorld!" -OutFile "helloworld.iss"
PS> iscc .\helloworld.iss

or run the iscc step from within your .ps1 script, if you prefer.或者,如果您愿意,可以从.ps1脚本中运行iscc步骤。

If you want to parse command line arguments from code in inno, then use a method similar to this. 如果要从inno中的代码解析命令行参数,请使用与此类似的方法。 Just call the inno script from the command line as follows: 只需从命令行调用inno脚本,如下所示:

C:\MyInstallDirectory>MyInnoSetup.exe -myParam parameterValue

Then you can call the GetCommandLineParam like this wherever you need it: 然后你可以在任何需要的地方调用GetCommandLineParam:

myVariable := GetCommandLineParam('-myParam');

//================================================================== // ================================================ ==================

{ 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 arry 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;

Hope this helps... 希望这可以帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将带有值的命令行参数传递给 Inno Setup Compiler,以便我可以在我的代码中使用它们? - How can I pass command line parameters with a value to the Inno Setup Compiler, so I can use them in my code? 如何在Inno Setup中不使用批处理文件的情况下执行命令行工具 - How do you execute command line tools without using batch file in Inno Setup 在 Inno Setup 脚本中使用 Inno Setup 编译器命令行上指定的路径/值 - Using path/value specified on Inno Setup compiler command-line in Inno Setup script 是否可以使用 Inno Setup 接受自定义命令行参数 - Is it possible to accept custom command line parameters with Inno Setup 在 Inno Setup 中创建使用命令行参数执行程序的快捷方式 - Creating a shortcut to execute a program with command-line parameters in Inno Setup Inno Setup - 如何将命令行参数传递给代码以创建 txt 文件? - Inno Setup - how to pass a command line parameter to the code to create a txt file? Inno设置命令行进度 - Inno setup command line progress 如何使用Inno Setup将命令传递到Windows中的Cygwin控制台 - How do you pass commands to a Cygwin console in Windows using Inno Setup 如何通过Inno Setup中的“Run - &gt; Parameters”传递参数? - How to pass parameter through “Run-->Parameters” in Inno Setup? 如何将参数从 Java FX Ant 任务传递到 Inno Setup? - How to pass parameters from Java FX Ant task to Inno Setup?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM