I am trying to start the terminal and run a command automatically by using Runtime.getRuntime().exec()
, but it gives me following exceptions:
java.io.IOException: Cannot run program "/Applications/Utilities": error=13, Permission denied
I found the terminal app and changed permission to read&write
since I have the administrator account, but it still gives me the same exception.
I tried to open other document on my mac using the same way, it shows up to have the same exception. Is there any other way I can execute commands on terminal at runtime?
Here is the code I have :
import java.io.IOException;
public class OpenTerminal {
public static void main(String[] args) {
OpenTerminal ot = new OpenTerminal();
try {
Runtime.getRuntime().exec("/Applications/Utilities open - a Terminal");
} catch (IOException e) {
e.printStackTrace();
}
}
}