下面是我正在运行的代码片段.我是否使用数组pf字符串(cmd)或它是单个字符串我得到一个例外(见下文),同时有一个无密码登录到目标Linux系统.
private static int bringHostFile() {
try {
String[] cmd ={"ssh" , "root@im6-64s" , "/root/bring_hosts"};
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
String s = null;
// read the output from the command
if ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
// read any errors from the attempted command
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
}
catch (IOException e) {
e.printStackTrace();
System.exit(-1);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
例外: …