I am using Mac OS Lion, with java version 1.6.0_26
I am creating a small Mac application for Java with a main menu for the user, so he can choose several options.
One of them is to install the application using .pkg
Everything worked perfectly with these commands:
File instFolder = new File(System.getProperty("user.dir") + "/foldername/appInstaller.pkg"); String s = "open "+ instFolder.toString(); Process p = Runtime.getRuntime().exec(s);
Then I realized that there is a problem when the folder name has spaces, or if I copy this java file with the necessary subfolders to a USB drive with the name "NO NAME" as a name (or some name with spaces).
Because s will become something like:
open / Volumes / NO NAME / folder name /appInstaller.pkg
or
open / Users / user1 / Desktop / Folder Name / appInstaller.pkg
So when you start the p-process, the command will end the place where the first place appears in the path
open / Volumes / NO
or
open / Users / user1 / Desktop / folder
To fix this, I changed the definition of s to something like this:
String s = "open "+ "\"" + instFolder.toString() + "\"";
He stopped working normally. It is strange that if I copy the value of s (after creating the variable s) and paste it into the terminal, it will work:
open "/ Users / user1 / Desktop / folder name /appInstaller.pkg"
but starting it from Java, it does not work.
could you help me?
Thanks.
source share