Commandline parameters

Got a problem you cannot solve? Try here.
zchris
Posts: 92
Joined: Wed Feb 23, 2005 3:16 am
Location: Austria

Commandline parameters

Postby zchris » Thu Sep 01, 2005 7:51 am

I can pass commandline parameters to my setup by running:

Code: Select all

setup.exe PARAM1=value PARAM2=value

In my script I want to use PARAM1 if it was specified, otherwise I want to use my own default.

First I need to define the variable in my script:

Code: Select all

Set Variable PARAM1 to $PARAM1$

(I set it to $PARAM1$ so that I don't loose the value from the command line)

Now PARAM1 either contains the value that was specified on the command line or the string "$PARAM1$".

Next I want to set my default:

Code: Select all

If Variable PARAM1 equals $PARAM1$
  Set Variable PARAM1 to my default value
end

This will obviously not work as it is always true - but how do I specify "$PARAM1$" (the string, not the variable) in the if command? Is the some escape character for the $?

Thanks!

jimo
Posts: 342
Joined: Fri Aug 19, 2005 10:59 am
Location: Atlanta, GA
Contact:

Re: Commandline parameters

Postby jimo » Thu Sep 01, 2005 8:34 am

zchris wrote:I can pass commandline parameters to my setup by running:

Code: Select all

setup.exe PARAM1=value PARAM2=value

In my script I want to use PARAM1 if it was specified, otherwise I want to use my own default.

First I need to define the variable in my script:

Code: Select all

Set Variable PARAM1 to $PARAM1$

(I set it to $PARAM1$ so that I don't loose the value from the command line)

Now PARAM1 either contains the value that was specified on the command line or the string "$PARAM1$".

Next I want to set my default:

Code: Select all

If Variable PARAM1 equals $PARAM1$
  Set Variable PARAM1 to my default value
end

This will obviously not work as it is always true - but how do I specify "$PARAM1$" (the string, not the variable) in the if command? Is the some escape character for the $?

Thanks!


Why not put the "If statement" as the first line in the script so you get the command line right away and act upon it. I don't think you need the extra lines of code, or maybe something like

Code: Select all

IF Variable PARAM1 equals
  Set Variable CL_PARAM1 to my default value
else
  Set Variable CL_PARAM1 to $PARAM1$
end

sinan
Site Admin
Posts: 1020
Joined: Sat Nov 13, 2004 8:12 am
Contact:

Postby sinan » Thu Sep 01, 2005 8:44 am

Command line parameter handling is now easier, in InstallAware 2005 Second Edition.

First, initialize the variable in the script to its default value, using Set Variable. Then, modify the variable as you see fit in the script.

Now, if that variable is specified on the command line, its value will be locked throughout the script execution. All Set Variable commands on that variable will return without actually updating the variable.

zchris
Posts: 92
Joined: Wed Feb 23, 2005 3:16 am
Location: Austria

Re: Commandline parameters

Postby zchris » Fri Sep 02, 2005 2:07 am

jimo wrote:Why not put the "If statement" as the first line in the script so you get the command line right away and act upon it. I don't think you need the extra lines of code, or maybe something like

Code: Select all

IF Variable PARAM1 equals
  Set Variable CL_PARAM1 to my default value
else
  Set Variable CL_PARAM1 to $PARAM1$
end


That would be nice - however InstallAware won't let you use a variable unless you declare it first by using a set command. Your code would produce a compile time error.

zchris
Posts: 92
Joined: Wed Feb 23, 2005 3:16 am
Location: Austria

Postby zchris » Fri Sep 02, 2005 2:20 am

sinan wrote:Command line parameter handling is now easier, in InstallAware 2005 Second Edition.

First, initialize the variable in the script to its default value, using Set Variable. Then, modify the variable as you see fit in the script.

Now, if that variable is specified on the command line, its value will be locked throughout the script execution. All Set Variable commands on that variable will return without actually updating the variable.


I am using InstallAware 2005 Second Edition - however it does not work as you say. I just tried it and all variables can be changed even if they are specified on the command line.

Actually I would not want it to work the way you described it. I have a "Set Variable ALLUSERS to TRUE" in my code. A commandline parameter ALLUSERS=FALSE could simply override that value even though the setup expects to be installed for all users.

OK, now how do I test if the PARAM1 contains the string "$PARAM1$"?

zchris
Posts: 92
Joined: Wed Feb 23, 2005 3:16 am
Location: Austria

List index out of bounds(0)

Postby zchris » Fri Sep 02, 2005 2:48 am

I stumbled across a bug when I tried to get this code to work:

Code: Select all

Set Variable D to $
Set Variable PARAM1 to $PARAM1$
If Variable PARAM1 equals $D$PARAM1$D$
  Set Variable PARAM1 to my default value
end

InstallAware will no longer open my project - it gives me the error "List index out of bounds(0)". After that it will show the error even if you just start InstallAware from the start menu.

I was able to get things working again by editing the mia with notepad.

sinan
Site Admin
Posts: 1020
Joined: Sat Nov 13, 2004 8:12 am
Contact:

Postby sinan » Fri Sep 02, 2005 5:02 am

I forgot to mention, the variables are locked only when running silent installations. Variable values are not locked when not running silent installations (the /s command line parameter) as this would be quite confusing.

Does this help?

zchris
Posts: 92
Joined: Wed Feb 23, 2005 3:16 am
Location: Austria

Postby zchris » Mon Sep 05, 2005 2:42 am

sinan wrote:I forgot to mention, the variables are locked only when running silent installations. Variable values are not locked when not running silent installations (the /s command line parameter) as this would be quite confusing.


OK. I still have the same problem. I am running a normal (not silent) setup and I want to either read in the command line paramters or use my own defaults.

Thanks.

sinan
Site Admin
Posts: 1020
Joined: Sat Nov 13, 2004 8:12 am
Contact:

Postby sinan » Mon Sep 05, 2005 4:03 am

In that case, I recommend you access the command line directly. Just read the value of the pre-defined variable CMDLINE, and search for the text you are looking for using the Parse String command.

zchris
Posts: 92
Joined: Wed Feb 23, 2005 3:16 am
Location: Austria

Postby zchris » Mon Sep 05, 2005 6:17 am

OK, thanks. I will take a look at that.

Do you know if there is a (possibly undocumented) variable that contains the $ character (like $NEWLINE$ that contains a newline)?

I want to assign it to a variable and

Code: Select all

Set Variable D to $

does not work.

Thanks!

sinan
Site Admin
Posts: 1020
Joined: Sat Nov 13, 2004 8:12 am
Contact:

Postby sinan » Mon Sep 05, 2005 8:11 pm

No, there is none - however the variable assignment may fail because the $ is a reserved symbol.


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 22 guests