1

I am working on a JavaFX application and I cannot figure out how to write a ssh command on a launched terminal on iOS.

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();
}

launched is always 0, so I can not write to the process anymore.

The full code is here https://github.com/gadelkareem/aws-client/blob/dev/src/main/java/com/gadelkareem/awsclient/application/Controller.java

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Gadelkareem
  • 1,067
  • 13
  • 30

1 Answers1

3

As this suggested. I must use /usr/bin/osascript

try {
    final ProcessBuilder processBuilder = new ProcessBuilder("/usr/bin/osascript",
            "-e", "tell app \"Terminal\"",
            "-e", "set currentTab to do script " +
            "(\"/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() + "\")",
            "-e", "end tell");
    final Process process = processBuilder.start();
    process.waitFor();

} catch (Exception e) {
    e.printStackTrace();
}
Community
  • 1
  • 1
Gadelkareem
  • 1,067
  • 13
  • 30