You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The exit status sometimes return -1 when i use jsch.
Even though -1 is returned, the script executes normally.
When exit status return -1, should I think the script executed successfully or failed? Please help me, thanks.
The implementation is as follows: Session session = null; ChannelExec channelExec = null; int exitStatus; String responseMsg = null; try { JSch jSch = new JSch(); jSch.addIdentity(null, prvKey.getBytes(), null, null); session = jSch.getSession(user, host, port); session.setConfig("StrictHostKeyChecking", "no"); session.connect(CONNECT_TIMEOUT); channelExec = (ChannelExec) session.openChannel("exec"); InputStream inputStream = channelExec.getInputStream(); channelExec.setCommand(cmd); channelExec.connect(); byte[] tmp = new byte[1024]; while (true) { while (inputStream.available() > 0) { int i = inputStream.read(tmp, 0, 1024); if (i < 0) { break; } responseMsg = new String(tmp, 0, i); } if (channelExec.isClosed()) { if (inputStream.available() > 0) { continue; } exitStatus = channelExec.getExitStatus(); break; } try { Thread.sleep(1000); } catch (Exception e) { // Ignore exception. } } } finally { if (channelExec != null) { channelExec.disconnect(); } if (session != null) { session.disconnect(); } }
The text was updated successfully, but these errors were encountered:
The exit status sometimes return -1 when i use jsch.
Even though -1 is returned, the script executes normally.
When exit status return -1, should I think the script executed successfully or failed? Please help me, thanks.
The implementation is as follows:
Session session = null; ChannelExec channelExec = null; int exitStatus; String responseMsg = null; try { JSch jSch = new JSch(); jSch.addIdentity(null, prvKey.getBytes(), null, null); session = jSch.getSession(user, host, port); session.setConfig("StrictHostKeyChecking", "no"); session.connect(CONNECT_TIMEOUT); channelExec = (ChannelExec) session.openChannel("exec"); InputStream inputStream = channelExec.getInputStream(); channelExec.setCommand(cmd); channelExec.connect(); byte[] tmp = new byte[1024]; while (true) { while (inputStream.available() > 0) { int i = inputStream.read(tmp, 0, 1024); if (i < 0) { break; } responseMsg = new String(tmp, 0, i); } if (channelExec.isClosed()) { if (inputStream.available() > 0) { continue; } exitStatus = channelExec.getExitStatus(); break; } try { Thread.sleep(1000); } catch (Exception e) { // Ignore exception. } } } finally { if (channelExec != null) { channelExec.disconnect(); } if (session != null) { session.disconnect(); } }
The text was updated successfully, but these errors were encountered: