FMA
FMA

Reputation: 51

How to pass parameter value from compiler to the script?

I need to pass a parameter value from compiler to the [Files] section of my compiled script, such as one can do at setup runtime using the {param:...} constant in their script. My idea is compiling my script e.g. this way (which fails to execute):

compil32 "script.iss" -CmdPath "D:\Samples"

Having in my script something like this (it won't work as it's for setup runtime not compilation time):

#define DefPath "D:\Install"

[Files]
Source: {param:CmdPath|DefPath}\Install\App.exe; DestDir: {app};

Upvotes: 1

Views: 517

Answers (1)

TLama
TLama

Reputation: 76693

You can build your setup by using ISCC compiler passing it the path through the /D parameter. That will declare a public #define for your script. Since the #define can be redeclared by the script, you need to ensure its conditional declaration for the default value you want to have. For example:

#ifndef SrcPath
  #define SrcPath "C:\DefaultPath\"
#endif

[Files]
Source: {#SrcPath}App.exe; DestDir: {app}

Then building the setup this way will use the #define from the script:

ISCC.exe Script.iss

Whilst building it this way will use the #define declared by the passed parameter value:

ISCC.exe Script.iss /DSrcPath="C:\AnotherPath\"

Upvotes: 2

Related Questions