title: Launch terminal on OS X and run commands using Java
body: <p>I am working on a JavaFX application and I cannot figure out how to write a ssh command on a launched terminal on iOS. </p>
  
  <pre><code>try {
      Process process = Runtime.getRuntime().exec("/usr/bin/open -a /Applications/Utilities/Terminal.app /bin/bash");
      int launched = process.waitFor();
      BufferedWriter terminal = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
      System.out.println(launched);
      terminal.write("/usr/bin/ssh -o CheckHostIP=no -o TCPKeepAlive=yes -o StrictHostKeyChecking=no -o ServerAliveInterval=120 -o ServerAliveCountMax=100 -i ~/.aws/.ec2/dublin.pem ubuntu@"
          + selectedRow.get(publicDnsNameIndex).getValue() + "\n");
  } catch (Exception e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p><code>launched</code> is always 0, so I can not write to the process anymore. </p>
  
  <p>The full code is here <a href="https://github.com/gadelkareem/aws-client/blob/dev/src/main/java/com/gadelkareem/awsclient/application/Controller.java" rel="nofollow">https://github.com/gadelkareem/aws-client/blob/dev/src/main/java/com/gadelkareem/awsclient/application/Controller.java</a></p>