[ 
https://issues.apache.org/jira/browse/SSHD-1068?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17186662#comment-17186662
 ] 

Lyor Goldstein commented on SSHD-1068:
--------------------------------------

You are closing the channel immediately after calling 
{{channel.open().verify()}} which means you are "killing" it while the 
+background+ channel data pumper is attempting to work. Look at the way 
{{executeRemoteCommand}} works (even if you don't want to use it) - it  waits 
for the peer to close the channel:

{code:java}
 try (ClientChannel channel = createExecChannel(command)) {
            channel.setOut(channelOut);
            channel.setErr(channelErr);
            channel.open().await();t

            Collection<ClientChannelEvent> waitMask = 
channel.waitFor(REMOTE_COMMAND_WAIT_EVENTS, 0L);
            if (waitMask.contains(ClientChannelEvent.TIMEOUT)) {
                throw new SocketTimeoutException("Failed to retrieve command 
result in time: " + command);
            }
}
{code}

> ChannelExec not showing the output
> ----------------------------------
>
>                 Key: SSHD-1068
>                 URL: https://issues.apache.org/jira/browse/SSHD-1068
>             Project: MINA SSHD
>          Issue Type: Question
>    Affects Versions: 2.5.1
>            Reporter: Arpan
>            Priority: Minor
>
> I have just started using apache-mina ssh client and ran into a issue where 
> the command output is not printing. Here is the sample code - 
> {code:java}
> class LibraryBasicTest {
>       private static final String USER = "luser";
>       private static final String HOST = "192.168.0.179";
>       private static final int PORT = 22;
>       private static final long DEFAULT_CONNECT_TIMEOUT = 3L;
>       private static final long DEFAULT_AUTH_TIMEOUT = 3L;
>       private static final long DEFAULT_EXEC_TIMEOUT = 3L;
>       @Test
>       void basic_user_pass_ssh_conn_tests() {
>               SshClient sshClient = SshClient.setUpDefaultClient();
>               sshClient.start();
>               ClientSession session = null;
>               try {
>                       session = sshClient.connect(USER, HOST, 
> PORT).verify(DEFAULT_CONNECT_TIMEOUT, TimeUnit.SECONDS)
>                                       .getClientSession();
>                       session.addPasswordIdentity("P@ssw0rd");
>                       session.auth().verify(DEFAULT_AUTH_TIMEOUT, 
> TimeUnit.SECONDS);
>                       
>                       ChannelExec channel = session.createExecChannel("sleep 
> 2;echo \"Hello World!\" \n");
>                       channel.setUsePty(true);
>                       channel.setOut(System.out);
>                       channel.setErr(System.err);
>                       channel.open().verify(DEFAULT_EXEC_TIMEOUT, 
> TimeUnit.SECONDS);
>               } catch (IOException e) {
>                       e.printStackTrace();
>               } finally {
>                       if (null != session) {
>                               try {
>                                       session.close();
>                               } catch (IOException e) {
>                                       e.printStackTrace();
>                               }
>                       }
>               }
>               sshClient.stop();
>       }
> }
> {code}
> What am I missing here ?
> P.S. The below command works though but not planing to use it until it is the 
> only way.
> {code:java}session.executeRemoteCommand("echo \"Hello World!\"");{code} 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to