0
我檢查在Java中遠程使用JSch服務器的文件修改的狀態。除了輸出外,我還在檢查退出代碼。 在測試服務器上運行良好,並給予退出代碼爲0,生產服務器是扔退出代碼-1。我如何獲得關於這個-1及其含義的更多細節。SSH命令-1
這裏是我的代碼,敏感區域移除。
如何獲得最後一行getExitStatus
更多細節。
JSch js=new JSch();
Session s = js.getSession(username, host, 22);
s.setPassword(password);
Properties ssconfig = new Properties();
ssconfig.put("StrictHostKeyChecking", "no");
s.setConfig(ssconfig);
s.connect();
Channel c = s.openChannel("exec");
ChannelExec ce = (ChannelExec) c;
ce.setCommand("cd <some file dir> && date && ls -ltr");
ce.setErrStream(System.err);
ce.connect();
/*
* temporary test print
*/
BufferedReader reader = new BufferedReader(new InputStreamReader(ce.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
/*
* end of temporary print
*/
ce.disconnect();
s.disconnect();
System.out.println("Exit code: " + ce.getExitStatus());
return ce.getExitStatus();