Skip to content

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

Open
@DarkFrank

Description

@DarkFrank

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions