[
https://issues.apache.org/jira/browse/SSHD-1064?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17184084#comment-17184084
]
Lyor Goldstein edited comment on SSHD-1064 at 8/25/20, 2:09 PM:
----------------------------------------------------------------
{quote}
This is supposed to work, isn't it?
{quote}
It's not a yes/no question - actually, it depends on the SSH server. The
exception you are getting is due to the fact that the SSH server did not return
an exit status code
{code:java}
/**
* @return The signaled exit status via "exit-status" request -
{@code null} if not signaled
*/
Integer getExitStatus();
/**
* Execute a command that requires no input and redirects its STDOUT/STDERR
streams to the user-provided ones
*
* @param command The command to execute - without a terminating LF
* @param stdout Standard output stream - if {@code null} then stream
data is ignored. <B>Note:</B> if the
* stream is not {@code null} then it will be left
<U>open</U> when this method returns or
* exception is thrown
* @param stderr Error output stream - if {@code null} then stream
data is ignored. <B>Note:</B> if the stream
* is not {@code null} then it will be left <U>open</U>
when this method returns or exception is
* thrown
* @param charset The command {@link Charset} for output/error - if
{@code null} then US_ASCII is assumed
* @throws IOException If failed to execute the command or got a non-zero
exit status
* @see ClientChannel#validateCommandExitStatusCode(String,
Integer) validateCommandExitStatusCode
*/
default void executeRemoteCommand(
String command, OutputStream stdout, OutputStream stderr, Charset
charset)
throws IOException {
...
}
{code}
Signalling an exit status is optional according to the standard, so the SSH
server is not violating it by not sending it. Why it does not return such a
status for the "ps aux" command is not in the scope of this project. You chose
to use the simple client - which is aptly named so - it assumes some "default"
behavior - which in this case does not apply. You can achieve what you want by
implementing your own code execution wrapper and decide how to handle the lack
of an exit status yourself.
was (Author: lgoldstein):
{quote}
This is supposed to work, isn't it?
{quote}
It's not a yes/no question - actually, it depends on the SSH server. The
exception you are getting is due to the fact that the SSH server did not return
an exit status code
{code:java}
/**
* @return The signaled exit status via "exit-status" request -
{@code null} if not signaled
*/
Integer getExitStatus();
{code}
Signalling an exit status is optional according to the standard, so the SSH
server is not violating it by not sending it. Why it does not return such a
status for the "ps aux" command is not in the scope of this project. You chose
to use the simple client - which is aptly named so - it assumes some "default"
behavior - which in this case does not apply. You can achieve what you want by
using the full-blown code and decide how to handle the lack of an exit status
yourself.
> Mutliple commands in one session do not work
> ---------------------------------------------
>
> Key: SSHD-1064
> URL: https://issues.apache.org/jira/browse/SSHD-1064
> Project: MINA SSHD
> Issue Type: Bug
> Affects Versions: 2.5.1
> Reporter: Björn Kautler
> Assignee: Lyor Goldstein
> Priority: Minor
>
> I tried to do this:
> {code:java}
> SshClient.setUpDefaultSimpleClient().use { ssh ->
> ssh.sessionLogin("server.company.com", "user", "p@ssw0rd").use { session ->
> println(session.executeRemoteCommand("id"))
> println(session.executeRemoteCommand("ps aux"))
> }
> }
> {code}
> (If you are not familiar with the syntax, it is Kotlin. The {{use}} works
> like a try-with-resources, I think the rest should be pretty obvious)
> This is supposed to work, isn't it?
> Yet it does not work.
> The first command works fine and then for the second command I get
> {{java.rmi.RemoteException: No exit status returned for command=ps aux}}.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]