Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过java Runtime.getRuntime().exec从windows连接到linux机器_Java_Linux_Windows - Fatal编程技术网

通过java Runtime.getRuntime().exec从windows连接到linux机器

通过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

嗨,我想通过java从windows连接到linux机器。我通过互联网和fide代码进行搜索,如:

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和许多其他工具都使用它)