So I am trying to make a universal app, and I am trying to make it have the ability to open applications. So, I figured out to make it open an application if it is one word, but with spaces, it never works. This is how I do it:
if(textField.getText().startsWith("application open")){
try {
String string1 = textField.getText().substring(17, textField.getText().length());
Runtime.getRuntime().exec("open /Applications/\"" + string1 + "\".app");
textArea.append("Opening application " + string1 + "..." + newline);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
If anyone could help me out, that would be great!
Thanks in advance,
Howard Stark
Use the version of
execthat takes aString[]:This works for me:
Whereas this doesn’t:
The latter can only use spaces to break up the command arguments, and so is parsed as the command open, followed by 2 arguments delimited by the space. The former – the version of
execthat takes aString[]– is passed each argument individually, and so doesn’t have this problem.