Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exit status return -1, should I think the script executed successfully or failed? #29

Open
DarkFrank opened this issue Oct 14, 2020 · 0 comments

Comments

@DarkFrank
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant