我正在研究JavaFX应用程序,我无法弄清楚如何在iOS上的已启动终端上编写ssh命令。
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
始终为0,因此我无法再写入该过程。
答案 0 :(得分:3)
正如this所建议的那样。我必须使用/ 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();
}