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();