<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to 14: int RunCommand fails with long output</title><link>https://sourceforge.net/p/sharpssh/bugs/14/</link><description>Recent changes to 14: int RunCommand fails with long output</description><atom:link href="https://sourceforge.net/p/sharpssh/bugs/14/feed.rss" rel="self"/><language>en</language><lastBuildDate>Thu, 05 Feb 2009 17:27:41 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/sharpssh/bugs/14/feed.rss" rel="self" type="application/rss+xml"/><item><title>int RunCommand fails with long output</title><link>https://sourceforge.net/p/sharpssh/bugs/14/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;If you use SshExe.RunCommand(string command, ref string StdOut, ref string StdErr) to execute a command that gives sufficiently long output (doesn't appear to be a fixed limit at the moment), then the function will hang.  The problem is related to reading the contents of STDERR - if nothing is received and STDERR stays open, the read loop will never return.&lt;/p&gt;
&lt;p&gt;I've spent some time trying to fix this, but don't know enough about the details to figure out why this is happening.  At the moment I've written a new version of RunCommand which returns the command return code, but doesn't use STDERR, but I would like to be able to fix the problem properly.&lt;/p&gt;
&lt;p&gt;My suspicion about what's happening is this: if the output is short enough that all of the STDOUT output is buffered before the code finishes reading it, the remote side will have closed STDERR, which stops it reading anymore.  However, if the output is large enough that any receive buffers are full, the code has to process some data before the remote side closes STDOUT/STDERR.  However, the line to read data from stderr will not return if no data has been received, or if the channel has not been closed.&lt;/p&gt;
&lt;p&gt;The code is stopped here in RunCommand...&lt;/p&gt;
&lt;p&gt;while (true)&lt;br /&gt;
{&lt;br /&gt;
if (o != -1) o = stdout.Read(buff, 0, buff.Length);&lt;br /&gt;
if (o != -1) sbStdOut.Append(Encoding.ASCII.GetString(buff, 0, o));&lt;br /&gt;
if (e != -1) e = stderr.Read(buff, 0, buff.Length);                             // THIS LINE NEVER COMPLETES&lt;br /&gt;
if (e != -1) sbStdErr.Append(Encoding.ASCII.GetString(buff, 0, e));&lt;br /&gt;
if ((o == -1) &amp;amp;&amp;amp; (e == -1)) break;&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;The loop that doesn't complete is in PipedInputStream.read() - m_in is set to -1 and never gets incremented as no data is received.&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Richard Lawley</dc:creator><pubDate>Thu, 05 Feb 2009 17:27:41 -0000</pubDate><guid>https://sourceforge.net335a3e61070bac0c99be6f2f446a60afa4164434</guid></item></channel></rss>