macinta
Posts: 9
Joined: Thu Jun 07, 2007 8:59 pm
Contact: Website

Custom action command line arguments split incorrectly?

Hello,

I'm evaluating Advanced Installer for use in packaging a Java product and I'm having problems getting it to pass multiple command line arguments to a custom action. I have a Jar file that I want to run as a custom action at Commit time and I want to be able to pass some things to it on the command line, specifically the location where the application was installed and the type of application that was installed (e.g., I would pass in "demo" for the demo version of my product). I have tried a variety of different combinations but I can't seem to get Advanced Installer to pass these two pieces of information as distinct command line arguments.

Here is one configuration that I tried:
  • Type: File installed with the product
  • Source Path: APPDIR\jre\bin\java.exe
  • Source Type: Executable (*.exe)
  • Command Line: -jar [&commit.jar] "[APPDIR]" demo
When I run the installer, it successfully launches the Jar, but Java only gets a single command line argument:

Code: Select all


arg[0] = C:\Program Files\Pensamos Digital, Inc\TMaps Test" demo

If I remove the quotes around [APPDIR], Java gets passed six command line arguments:

Code: Select all


arg[0] = C:\Program
arg[1] = Files\Pensamos
arg[2] = Digital,
arg[3] = Inc\TMaps
arg[4] = Test
arg[5] = demo

I have tried adding quotes around the other arguments as well, but that doesn't work either.

Is there some trick to passing in APPDIR as a distinct command line argument for a custom action? I have been quite happy with your installer thus far and would like to be able to use it for my product.

Thanks,
- Tim Macinta
gigi
Posts: 2103
Joined: Tue Apr 11, 2006 9:55 am
Contact: Website

Hi Tim,

Thank you for your interest in Advanced Installer.

Windows Installer when expands properties like APPDIR (that links to a folder location) puts a "\" character at the end (for example: "C:\Test\") and because of this java parse the command line incorrectly.

To verify you can try with: -jar "[&commit.jar]" param1 param2 as command line.

So you need to remove that "\" character first. To do this you can use a "ScriptInLine" custom action scheduled before your actual custom action. Use following code in the "Script Text" code:

Code: Select all

Session.Property("APPDIR") = Left(Session.Property("APPDIR"), Len(Session.Property("APPDIR")) - 1)
Also you need enclose all reference to files and folders into quotes.

Let me know if you encounter any problems.

Regards,
Gigi
______________
Gheorghe Rada
Advanced Installer Team
http://www.advancedinstaller.com
macinta
Posts: 9
Joined: Thu Jun 07, 2007 8:59 pm
Contact: Website

Gigi,

Thanks, that certainly explains things. Also, thank you for the fast reply.

I tried your fix but when I ran the package and it got to the inline script, I got the following error dialog:

There is a problem with this Windows Installer package.
A script required for this install to complete could not be
run. Contact your support personnel or package vendor.
All I did was add a "Script Inline" custom action in the "Commit" section before my own custom command and cut and paste your code into the "Script Text" field.

So based on your description of the problem, I tried a different approach by adding a space to the end of the command line parameter so that the backslash wouldn't be right before the quote: i.e., I used "[APPDIR] " instead of "[APPDIR]". That seems to work fine, so worst case scenario I can just modify my Jar file to expect an extra space at the end of each argument. I like your solution better, though, if you have any quick suggestions for what I might have done wrong.

Thanks,
- Tim Macinta
gigi
Posts: 2103
Joined: Tue Apr 11, 2006 9:55 am
Contact: Website

Hi Tim,

"Deferred" type of custom actions does not have access to the Windows Installer properties (like "APPDIR") and because of this the custom action fails.

So change the "Execution Options" of the custom action from "Commit" to "Immediate execution".

Let me know if you encounter any problems.

Regards,
Gigi
______________
Gheorghe Rada
Advanced Installer Team
http://www.advancedinstaller.com
macinta
Posts: 9
Joined: Thu Jun 07, 2007 8:59 pm
Contact: Website

Gigi,

Thanks, that did the trick.

- Tim Macinta

Return to “Common Problems”