add getExitStatus check

This commit is contained in:
Looly
2025-09-10 09:33:52 +08:00
parent 9116f26375
commit 10e662886b

View File

@@ -185,11 +185,17 @@ public class JschSession implements Session {
channel.setInputStream(null);
channel.setErrStream(errStream);
String result;
InputStream in = null;
try {
channel.connect();
in = channel.getInputStream();
return IoUtil.read(in, charset);
result = IoUtil.read(in, charset);
if(channel.getExitStatus() != 0){
throw new SshException("Execute command [{}] error, exit status is [{}]", cmd, channel.getExitStatus());
}
} catch (final IOException e) {
throw new IORuntimeException(e);
} catch (final JSchException e) {
@@ -200,6 +206,8 @@ public class JschSession implements Session {
channel.disconnect();
}
}
return result;
}
/**