gpt4 book ai didi

java - 在 OS X 上启动终端并使用 Java 运行命令

转载 作者:行者123 更新时间:2023-11-29 04:53:40 26 4
gpt4 key购买 nike

我正在开发 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,因此我无法再写入进程。

完整代码在这里https://github.com/gadelkareem/aws-client/blob/dev/src/main/java/com/gadelkareem/awsclient/application/Controller.java

最佳答案

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

关于java - 在 OS X 上启动终端并使用 Java 运行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34508525/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com