更具体地说,我真正想做的是打开两个新终端。从 terminal_1 我想 ssh @host1 并将程序 1 运行到 host1。从 terminal_2 我想 ssh @host2 并将程序 2 运行到 host2。我需要在终端 1 上查看程序 1 的输出,在终端 2 上查看程序 2 的输出。
(我设法打开了 xterm 和 ssh @host。我试图传递第二个命令“&&java echo_1”,但它什么也没做)
这是代码:
import java.io.*;
public class multi1 implements Runnable {
public void run() {
try {
String ss = null;
Runtime obj = null;
String[] newcmd = new String[]{"/usr/bin/xterm","-hold","-e","ssh andreas@192.168.0.0&&java echo_1"};
Process p = Runtime.getRuntime().exec(newcmd);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while ((ss = stdInput.readLine()) != null) {
System.out.println(ss);
}
}catch (IOException e) {
System.out.println("FROM CATCH" + e.toString());
}
}
public static void main(String[] args) throws Exception {
Thread th = new Thread(new multi1());
th.start();
//Thread th2 = new Thread(new multi1());
//th2.start();
}
}