我想通过一个java代码ssh abc@ubuntu来执行这个命令
我正在使用此代码,但它不能完全工作,它没有登录到服务器。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class JavaApplication4 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException, InterruptedException {
// TODO code application logic here
ProcessBuilder pb = new ProcessBuilder("ssh","usmanmahmood@ubuntu");
//pb.redirectErrorStream(); //redirect stderr to stdout
Process process = pb.start();
InputStream inputStream = process.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line = null;
while((line = reader.readLine())!= null) {
System.out.println(line);
}
int waitFor = process.waitFor();
}
}
请告诉我错误,