PDA

View Full Version : Can't get Execute Process to work



thorne
07-30-2004, 01:42 PM
UPDATE - I got the BAT file to execute by making the 1st argument:

/c ""$P(absoluteInstallLocation)/...../x.bat""

Note I have to use 2 sets of double quotes. But now I can't get additional arguments to work correctly. I have this 2nd argument:

$P(absoluteInstallLocation)

but what happens in the BAT file is that this argument is received with a double quote preceding it. I can't figure out from where it's coming. Anyone know?

ORIGINAL POST...

(Windows) I've got an Execute Process product bean with these properties, but it seems that the .BAT file never executes. Log file shows no output from the .BAT file. Would appreciate some help. Thanks, Thorne

Command = cmd
Arguments (1) =
/c "$P(beanLdapConfigurationFiles.installLocation)/LDAP_configuration.bat
$P(absoluteInstallLocation) $W(beanGetRegistryEntryForLdapLocation.value)/bin $P(absoluteInstallLocation)/$V(LOG_FILE)"
Bundle Executable = False
Stdout = $V(LOG_FILE)
Stderr = $V(LOG_FILE)
Wait = True
Runtime = Install

where:
$P(beanLdapConfigurationFiles.installLocation) = $P(absoluteInstallLocation)/ConfigurationFiles/LDAP

Now, it gets worse. I got the BAT file to execute, but now Windows returns an error because there is a blank in the string that resolves from a $P value (and Windows thinks that's the end of a command, but it's just part of the path). This resolved $P string needs itself to be wrapped in double quotes. I already have double quotes around the $P value in the IS argument, so how do I get this 2nd set of quotes in an IS argument string?

CharlesW
08-02-2004, 09:12 AM
Be sure that you have each and every argument on a separate line when specifying. For instance:

/c "$P(beanLdapConfigurationFiles.installLocation)/LDAP_configuration.bat"
"$P(absoluteInstallLocation)"
"$W(beanGetRegistryEntryForLdapLocation.value)/bin" "$P(absoluteInstallLocation)/$V(LOG_FILE)"

Basically, you should have 5 separate lines when specifying your arguments. Let me know if this does not help.

thorne
08-02-2004, 09:46 AM
Charles, Doesn't work. I get this error:

'C:\Program' is not recognized as an internal or external command, operable program or batch file.

which means that I need another pair of double quotes somewhere. I see this message in the command window where I start the install using "java -Dis.debug=1 -cp setup.jar run". I believe the message is coming from the BAT file which would mean that the arguments aren't getting sent to the BAT file correctly. I've tried setting the Stdout/Stderr Destination properties for this bean, but nothing additional gets logged (but worse, all the IS log output before the BAT file output is deleted).

Thanks for any help you can provide because my deadline on this project is this Friday. Thorne

CharlesW
08-02-2004, 10:03 AM
Now that I think about it, I seem to remember an issue with trying to launch "cmd" directly using the java API Runtime.exec(). Try this: First eliminate "/c" entirely. Specfy the following values for the exec action bean:

command = "$P(beanLdapConfigurationFiles.installLocation)/LDAP_configuration.bat"
arg1= "$P(absoluteInstallLocation)"
arg2="W(beanGetRegistryEntryForLdapLocation.value)/bin"
arg3="$P(absoluteInstallLocation)/$V(LOG_FILE)"
Bundle Executable = False
Stdout = c:\stdout.txt
Stderr = c:\stderr.txt
Wait = True
Runtime = Install

thorne
08-02-2004, 10:19 AM
That change causes a Java exception:

(Aug 2, 2004 10:07:34 AM), , com.installshield.product.actions.ExecAction, err, com.installshield.util.ProcessExecException
STACK_TRACE: 14
com.installshield.util.ProcessExecException
at com.installshield.util.ProcessExec.executeProcess(Unknown Source)
at com.installshield.product.actions.ExecAction.executeProcess(Unknown Source)
at com.installshield.product.actions.ExecAction.install(Unknown Source)
at com.installshield.product.service.product.PureJavaProductServiceImpl.installProductAction(Unknown Source)
at com.installshield.product.service.product.PureJavaProductServiceImpl$InstallProduct.getResultForProductAction(Unknown Source)
at com.installshield.product.service.product.InstallableObjectVisitor.visitComponent(Unknown Source)
at com.installshield.product.service.product.InstallableObjectVisitor.visitInstallableComponents(Unknown Source)
at com.installshield.product.service.product.InstallableObjectVisitor.visitProductBeans(Unknown Source)
at com.installshield.product.service.product.PureJavaProductServiceImpl$InstallProduct.install(Unknown Source)
at com.installshield.product.service.product.PureJavaProductServiceImpl$Installer.execute(Unknown Source)
at com.installshield.wizard.service.AsynchronousOperation.run(Unknown Source)
at java.lang.Thread.run(Thread.java:534)

and this error in STDOUT:

java.io.IOException: CreateProcess: "C:\Program Files\IBM\HCN/ConfigurationFiles/LDAP/LDAP_configuration.bat" "C:\Program Files\IBM\HCN" "/bin" "C:\Program Files\IBM\HCN\HcnAdminDashboardLog.txt" error=267

Also, if I don't create a cmd.exe environment, I won't have a separate environment in which to manipulate environment variables.

CharlesW
08-02-2004, 10:27 AM
Does the command line "C:\Program Files\IBM\HCN/ConfigurationFiles/LDAP/LDAP_configuration.bat" "C:\Program Files\IBM\HCN" "/bin" "C:\Program Files\IBM\HCN\HcnAdminDashboardLog.txt"

look approximately correct? Does the batch file exist in this location when the exec action bean is called?

Lets try one other thing, for the command, specify the following. This should normalize the path:

command = "$N($P(beanLdapConfigurationFiles.installLocation)/LDAP_configuration.bat)"

thorne
08-02-2004, 10:46 AM
$N made no difference. Yes, the BAT does exist as a previous IS bean lays the file down.

The command line is correct. I can execute that command as is (though without double quotes around the arguments) and the BAT file runs as expected.

CharlesW
08-02-2004, 10:48 AM
Could you send me your project file, and the batch file you are using? I'll try to set up a test to reproduce the behavior.

thorne
08-02-2004, 10:56 AM
If I remove the double quotes from the Command property, the BAT file gets control (i.e. no Java exception), but then the arguments are not sent to the BAT file correctly:

Files\IBM\HCN"" was unexpected at this time.

which I believe is a result of executing this BAT file statement:

if "%1" == "" goto endLoop

What's your email address? Thanks, Thorne

Steff74
08-03-2004, 02:39 AM
I had the same problem - maybe its because $P(absoluteInstallLocation) is resolved on windows with \ as file delimiter and a combination of \ and / always resulted in a processexception. I created my own simple Process Executor which resolves all Variables and then converts \\ to /. Example: /**
* @see com.installshield.wizard.WizardBean#execute(com.installshield.wizard.WizardBeanEvent)
*/
public void execute(WizardBeanEvent event) {
if (command != null) {
command = event.getWizard().getServices().resolveString(command);
command = command.replace('\\', '/');
try {
Process process = Runtime.getRuntime().exec(command);

if (isWaitForCompletion()) {
try {
process.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}

}

I use this custom bean for example to registry a dll: regsvr32 /s /u "$P(absoluteInstallLocation)/native/WMIQuery.dll"

CharlesW
08-03-2004, 09:01 AM
steff74
I think $N(<path>) will eliminate this problem

Thorn,
Try eliminating all double quotest from the command and the arguments. When I do not wrap the command in double quotes, the batch file launches fine. Going on this, I assume that there is no need to wrap the arguments.

thorne
08-03-2004, 09:30 AM
Charles, I tried that and still had argument passing problems as mentioned in previous posts (in the case of the suggestion in your last post, the result is the ProcessExecException). Were you able to reproduce with the files I sent you?

Right now, I have a workaround though undesirable as it requires reengineering of my BAT files. The workaround is to pre-process the BAT file with an Ascii File Update product action that substitutes for what would normally be variables altered by parameters. The funny thing is that I found out yesterday that 2 other people in my department have had this same argument passing problem (on IS MultiPlatform v5.x) and have had to use this same workaround. Thorne

CharlesW
08-03-2004, 10:02 AM
I did not reproduce the issue exactly, but I think I see where the problem lies. The Java API Runtime.exec() automatically wraps all arguments in quotes if they contain a space, and this is probably causing a problem in the batch file. For instance, and argument of:

c:\this path\has spaces

will be passed as an argument as:

"c:\this path\has spaces"

I wrote a small java application to launch a batch file. This app uses Runtime.exec(command []). The batch file that I used echos the arguments to stdout. Any time an argument contains a space, I found that the the argument is automatically wraped in quotes. To work around this, you will probably have to use your current work around, or write your batch file with the knowledge that the arguments passed in will be wrapped in quotes.

thorne
08-03-2004, 10:26 AM
I think something additional is wrong because if I use no quotes in IS (and I guess I shouldn't have to if Java adds the quotes for me), the Java implementation in IS results in the exec exception I mentioned. I guess it's a problem for Windows to have each argument wrapped in its own quotes. My guess is that Windows wants all the arguments wrapped in a single pair of quotes.

Anyway, thanks for your help, Charles. My suggestion is to have the IS Test team see if they have enough Windows test cases to expose this problem.

Perucho
08-18-2006, 01:17 PM
When running a CMD batch file using Wizard Action "Execute Process" an error is generated. Does anyone know how to resolve this error?

Perucho
08-18-2006, 05:47 PM
I found the correct syntax to execute a cmd batch file.

Wizard Action "Execute Process"

Command: $N($V(IS_DESTINATION)\templates\lic.cmd)