cancel
Showing results for 
Search instead for 
Did you mean: 
anom217
Pilgrim

Getting Java Version

This isn't exactly related to InstallShield per se, but I was wondering if anyone else has found a solution to this in InstallShield.

I need to get the version of Java I am installing with my product. I'm only extracting Java to my product but not actually installing it on the system, so it won't have any values in the registry.

To get the version I use "pathtojava\java.exe -version > example.txt" on the command line. The problem is, the file is created but nothing is written to it, even though the command dialog will display the version info. I need it written to a file because I am assuming that reading the file is the only way to get results from a command line execution.

Does anyone have any idea on how to make this work? Or another way for InstallShield to get the version of Java?
Labels (1)
0 Kudos
8 Replies

Re: Getting Java Version

You could try java.exe -version 2> example.txt

This should redirect stderr I believe, and it worked for me with getting the version output from java.exe.
0 Kudos
anom217
Pilgrim

Re: Getting Java Version

that did it. thanks!
0 Kudos
RobertDickau
Pilgrim

Re: Getting Java Version

(As an alternative, would detecting the version of java.exe do it?)
0 Kudos
anom217
Pilgrim

Re: Getting Java Version

I did consider checking the version of Java.exe file. It has two different version properties, and the format is a bit different than what you typically see in JDK releases (1.6.0_20). Since I need to be logging this info as well, it was easier and better to get the more typical format of the Java version.

However, now I'm having a problem with the method suggested before. When I execute "pathtojava\java.exe -version 2> c:\sample.txt" from the command line, it works fine. But for some reason when using LaunchAppAndWait the file does not get created. LaunchAppAndWait returns 0, and I have a MessageBox displaying the exact command that is executed, and when I copy and execute it myself it works just fine. I even see the command prompt appear and the command executes normally from LaunchAppAndWait, but no file is created. I have no idea what's going wrong here, any ideas?
0 Kudos
RobertDickau
Pilgrim

Re: Getting Java Version

It might depend on the particular command; if the 2> redirect operator doesn't work directly as a command-line argument, perhaps try creating a batch file and launching that?
0 Kudos
anom217
Pilgrim

Re: Getting Java Version

Using the batch file worked. I still don't understand why InstallShield can't execute this directly. I would still prefer to have it all done within the InstallScript function rather than create a dependency on a batch file that has to be included in the MSI file, but this works for now. Thanks.
0 Kudos
RobertDickau
Pilgrim

Re: Getting Java Version

I think the issue is that redirect operators aren't handled by the CreateProcess or ShellExecute API functions that LaunchApplication uses, but instead gets handled by the command processor.

As a test, a custom action that launches
cmd.exe /c set > C:\vars.txt
seems to work, redirecting a list of environment variables to a file C:\vars.txt without needing a separate batch file...
0 Kudos
anom217
Pilgrim

Re: Getting Java Version

That worked as well, and is a better solution than creating a batch file on fly, thanks. Well from now on I'll know to us cmd.exe instead of calling my app in LaunchAppAndWait if I'm using redirects. I was puzzled for a while as to why they weren't working.
0 Kudos