通过java Runtime.getRuntime().exec从windows连接到linux机器
嗨,我想通过java从windows连接到linux机器。我通过互联网和fide代码进行搜索,如:通过java Runtime.getRuntime().exec从windows连接到linux机器,java,linux,windows,Java,Linux,Windows,嗨,我想通过java从windows连接到linux机器。我通过互联网和fide代码进行搜索,如: public void testExec() throws IOException, InterruptedException{ Process p = Runtime.getRuntime().exec("ssh myhost"); PrintStream out = new PrintStream(p.getOutputStream()); BufferedRead
public void testExec() throws IOException, InterruptedException{
Process p = Runtime.getRuntime().exec("ssh myhost");
PrintStream out = new PrintStream(p.getOutputStream());
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
out.println("ls -l /home/me");
while (in.ready()) {
String s = in.readLine();
System.out.println(s);
}
out.println("exit");
p.waitFor();
}
但我不明白如何设置我的登录名和密码。有人用这种方式连接到linux吗?这太复杂了 您应该导入并使用它,它在java中运行得很好(EclipseAnt和许多其他工具都使用它)