KeyPairResourceLoader loader = SecurityUtils.getKeyPairResourceParser();
Collection<KeyPair> keys = loader.loadKeyPairs(null, Paths.get("~/.ssh/id_rsa"), FilePasswordProvider.EMPTY);
SshClient client = SshClient.setUpDefaultClient();
client.setKeyIdentityProvider(KeyIdentityProvider.wrapKeyPairs(keys));
client.start();
ClientSession session = client.connect("hudson", "xxx.xxx.xxx.xxx", 22).verify().getSession();
session.auth().verify();
ChannelExec channel = session.createExecChannel("ls");
//channel.setOut(System.err);
//channel.setErr(System.err);
channel.open().verify();
// Wait (forever) for the channel to close - signalling command finished
channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), 0L);
System.err.println(channel.getExitStatus());
I want to use a variable to receive the execution result of ls, but I don't know how to do it to get the execution result