[
https://issues.apache.org/jira/browse/SSHD-1112?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17250617#comment-17250617
]
Lyor Goldstein commented on SSHD-1112:
--------------------------------------
{quote}
when use different thread for waitFor() and inputstream, it work.
also it must call above two actions.
{quote}
Glad to hear it worked - in hindsight it makes sense - you need to avoid
closing the channel while you are busy reading. There may be other ways to do
this, but the one that is simplest (IMO) and works is to have 2 threads:
Thread A
* Sets up the channel's input/output/error streams
* Opens and waits for it to be open
* Spawns thread B
* Calls {{waitFor}} with {{ClientChannelEvent.CLOSED}}
* When event received, closes the chanel
Meanwhile, thread B consumes the channel data and then exits.
I believe this is outlined in [the
documentation|https://github.com/apache/mina-sshd/blob/master/docs/client-setup.md#running-a-command-or-opening-a-shell]
> Cannot return large output from channel.getInvertedOut() in version 2.6.0
> -------------------------------------------------------------------------
>
> Key: SSHD-1112
> URL: https://issues.apache.org/jira/browse/SSHD-1112
> Project: MINA SSHD
> Issue Type: Bug
> Affects Versions: 2.6.0
> Reporter: min yun law
> Priority: Major
> Fix For: 2.6.0
>
>
> The mina sshd version is 2.6.0 from github
> try to run the linux command "unzip -l bigzipfile.zip" in remote node, where
> the bigzipfile.zip had lots of files and folders which packed as one big zip
> file. the channel get stuck for a while and return exception : Pipe closed
> after 0 cycles
>
> Here is sample code:
> String getExecCommandResult(ClientChannel channel)
> {
> channel.open().await();
> Collection<ClientChannelEvent> waitMask = channel.waitFor(
> EnumSet.of(ClientChannelEvent.CLOSED, ClientChannelEvent.EXIT_STATUS,
> ClientChannelEvent.EXIT_SIGNAL, ClientChannelEvent.EOF),
> 0L //no TIMEOUT status returned if 0L
> );
>
> InputStream in = channel.getInvertedOut();
> String outputStr = "";
> if(in != null)
> {
> outputStr = readStream(in); //this is place that get stuck and exception is
> thrown
> }
> return outputStr;
> }
>
> String readStream(InputStream inputStream)
> {
> String line = null;
> String m_cmdOutput = "";
> try (BufferedReader bufReader = new BufferedReader(
> new InputStreamReader(inputStream)))
> {
> while ((line = bufReader.readLine()) != null)
> {
> m_cmdOutput += line + Constants.getDelimiter();
> }
> }
> catch (Exception ex)
> {
> //output the exception
> }
> return m_cmdOutput;
> }
>
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]