Page 1 of 1

Run Program and Command Line Arguments

Posted: Wed Aug 15, 2007 4:04 pm
by Craig Daniel
I'm making extensive use of the Run Program command in IA and I need to pass several command line arguments. Generally, my first parameter is the value $TARGETDIR$ followed by a trailing backslash, and that is followed by various options that make my EXE do different things. The problem I'm having is that it's difficult to get it to pass all the parameters correctly - they all get run together as one parameter (I have debug code in the EXE to print out the argument list).

Rather than put a bunch of examples here, I'd like to know exactly how InstallAware separates one paramater from the next. Or does it pass the string directly to the shell (after expanding any embedded variables)? The help topic has insufficient detail. I've tried using quotes "" to surround things with spaces in them (like TARGETDIR's value), and that actually appears to be part of the problem - what I see in my debug output is just one quote and the whole argument list is run together (like it's an unclosed quote).

Another thing that's very odd, is that the behavior seems to be different when I'm running as an upgrade versus running a fresh install. That may have something to do with the value of TARGETDIR though - which I am setting to the folder path where the older version is installed.

Trailing backslashes are evil

Posted: Wed Aug 15, 2007 6:55 pm
by Craig Daniel
Well, I solved my own problem with passing command line arguments.

It appears that IA just expands any embedded variables and then passes the resulting string as-is to the shell. What happened to me that caused so much confusion was that sometimes the path I was passing had a trailing backslash and sometimes it didn't.

What appears to happen when there's a trailing backslash is that Windows stupidly interprets that character as an escape character. So if you use quotes to surround a long path name that has spaces in it, and it ends with a trailing backslash, the shell ends up eating the trailing backslash and sticking a literal quote character into the command line - insane. The result is that you have a stray quote character in the command line which is not closed and everything from that point on runs together as one command line argument.

I solved it with an extra space (e.g. "$PATH_VARIABLE$ " arg2 arg3 ...) and fixed my EXE to trim off any trailing spaces on the path.