OS X で Runtime.exec() を使用してアプリケーションを開く方法は?
私のインストラクターは、私が Mac OS X を使用している間に彼が Windows を使用していることを除いて、その方法の例を教えてくれました。これまでにカスタマイズしたコードは次のとおりです。
public class Runtime_execution{
public static void main(String args[]){
Runtime rt = Runtime.getRuntime();
Process proc;
try{
if(System.getProperty("os.name").startsWith("Mac OS X")){
// run an OS specific program
proc = rt.exec("Contacts");
}else{
proc = rt.exec("gedit");
}
System.out.println("Before calling waitFor() method.");
proc.waitFor(); // try removing this line
System.out.println("After calling waitFor() method.");
}catch(Exception e){
System.out.println("Contacts is an unknown command.");
}
}
}
// find out what the os name is for Mac OS X
class Random{
public static void main(String args[]){
System.out.println(System.getProperty("os.name"));
}
}
プログラムを実行すると、出力が表示され続けました。
Contacts is an unknown command.
どうすればこれを修正できますか?