uttamgupta commented on issue #658:
URL: https://github.com/apache/mina-sshd/issues/658#issuecomment-2628646669

   Somehow I am able execute command remotely but not able to run interactive. 
I have read this document -
   
   ********************************************
    Running an interactive command/shell
   
   If one needs to parse the command/shell output and then respond by sending 
the correct input, the code must use separate thread(s) to read the 
STDOUT/STDERR and provide STDIN input. These threads must be up and running 
before opening the channel since data may start to pour in even before the 
await/verify call returns. If this data is not consumed at a reasonable pace, 
then channel may block and eventually even disconnect. Thus the thread(s) using 
the streams must be ready beforehand.
   
   // The same code can be used when opening a ChannelExec in order to run a 
single interactive command
   try (ClientChannel channel = session.createShellChannel(/* use internal 
defaults */)) {
       channel.setIn(...stdin...);
       channel.setOut(...stdout...);
       channel.setErr(...stderr...);
       ...spawn the servicing thread(s)....
       try {
           channel.open().verify(...some timeout...);
           // Wait (forever) for the channel to close - signalling shell exited
           channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), 0L);
       } finally {
           // ... stop the pumping threads ...
       }
   }
   In such cases it is recommended to use the inverted streams in the relevant 
threads
   
   // The same code can be used when opening a ChannelExec in order to run a 
single interactive command
   try (ClientChannel channel = session.createShellChannel(/* use internal 
defaults */)) {
       try {
           channel.open().verify(...some timeout...);
           
           spawnStdinThread(channel.getInvertedIn());
           spawnStdoutThread(channel.getInvertedOut());
           spawnStderrThread(channel.getInvertedErr());
   
           // Wait (forever) for the channel to close - signalling shell exited
           channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), 0L);
       } finally {
           // ... stop the pumping threads ...
       }
   }
   ********************************************
   
   I couldn't understand how to read and write commands in different threads. 
It would be great If any one could write a sample code.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to