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

Throw SSHClient.CommandFailed when the status code is non-zero #58

Merged
merged 2 commits into from
Feb 27, 2024

Conversation

Joannis
Copy link
Member

@Joannis Joannis commented Feb 27, 2024

No description provided.

@Joannis Joannis merged commit 6717f73 into main Feb 27, 2024
@Joannis Joannis deleted the jo/throw-exit-code-nonzero branch February 27, 2024 12:25
@BoringApp
Copy link

Thank you for your commit, but I am encountering an issue when using thesshClient.executeCommand method.
When a command fails (i.e., returns a non-zero exit code), I cannot capture the stdin or stderr output.
Am I using the wrong method?

do {
    let buf = try await client.executeCommand(command)
    let result = String(buffer: buf)
    return result
} catch let error as SSHClient.CommandFailed {
    // Missing error reason
    let message = "Command failed: `\(command)`, ExitCode: \(error.exitCode)"
    throw SessionError.executionFailed(message: message)
}

@Joannis
Copy link
Member Author

Joannis commented Oct 10, 2024

If you're interested in an output, rather than the convenience wrappers around it - look into executeCommandStream

@Joannis
Copy link
Member Author

Joannis commented Oct 10, 2024

Also noteworthy: #71 adds support for an stdin stream as well. But awaiting feedback

@BoringApp
Copy link

Thanks!

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

Successfully merging this pull request may close these issues.

2 participants