I've got a problem that I haven't seen anyone else come across, and that is using exec() to execute a Unix command, but with a variable path rather than a fixed one, when it contains spaces. Most solutions I've seen to paths with spaces in them involve manipulating the string, which I can't do equally with this. Here is my code.
void launchApp(String appName) {//TODO ignore spaces in names!
String[] cmd1 = new String[] {"chmod +x ", (new File(dataPath(""))).getParentFile().getParentFile().getParentFile().getParentFile().getPath() + "/" + appName + "/" + appName + ".app/Contents/MacOS/" + appName + ""};
String[] cmd2 = new String[] {"open ", (new File(dataPath(""))).getParentFile().getParentFile().getParentFile().getParentFile().getPath() + "/" + appName + "/" + appName + ".app"};
saveStrings("log0", cmd1);
try {
Runtime.getRuntime().exec(cmd1);
Runtime.getRuntime().exec(cmd2);
} catch (IOException e) {
println(e);
}
}
(Don't question the really complicated paths... they work just what I need to finish this prototype :) there would be variables to work around anyway)
By the way, I realize I can use ProcessBuilder rather than Runtime.getRuntime().exec() and I've seen that as a solution to the problem, but I have tried it and it doesn't work. I just have it in the exec() format while posting this.
Thank you for any help you can provide!
cmd1andcmd2. For exampleString path = new File(dataPath(""))/*...*/;String cmd1 = {"chmod", "+x", path};/*...*/Runtime.getRuntime().exec(cmd1);