title: Getting full command output from ShellStream of C# SSH.NET
body: <p>Using <a href="https://sshnet.codeplex.com/" rel="nofollow">Renci.SshNet</a> library. I am trying to execute some commands.
  After executing "command 1", I am executing "command 2" which takes more time.</p>
  
  <p>I am only getting the first line of the output. (<code>reader.ReadToEnd()</code> is not working in a proper way).</p>
  
  <p>I also tried <code>while (!reader.EndOfStream){ }</code> with no luck.</p>
  
  <p>I think it is because the delay of the response from server. When there is no response the stream read nothing and finishes.</p>
  
  <p>I found a solution </p>
  
  <pre><code>String tmp;
  TimeSpan timeout = new TimeSpan(0, 0, 3);
  while ((tmp = s.ReadLine()) != null)
  {
      Console.WriteLine(tmp);
  }
  </code></pre>
  
  <p>But this is not professional. I need some way in which the stream ends when it ends.</p>
  
  <pre><code>using (var vclient = new SshClient("host", "username", "password"))
  {
      vclient.Connect();
      using (ShellStream shell = vclient.CreateShellStream("dumb", 80, 24, 800, 600, 1024))
      {
          Console.WriteLine(SendCommand("comand 1", shell));
          Console.WriteLine(SendCommand("comand 2", shell));
          shell.Close();
      }
      vclient.Disconnect();
  }
  
  public static string SendCommand(string cmd, ShellStream sh)
  {
      StreamReader reader = null;
      try
      {
          reader = new StreamReader(sh);
          StreamWriter writer = new StreamWriter(sh);
          writer.AutoFlush = true;
          writer.WriteLine(cmd);
          while (sh.Length == 0)
          {
              Thread.Sleep(500);
          }
      }
      catch (Exception ex)
      {
          Console.WriteLine("exception: " + ex.ToString());
      }
      return reader.ReadToEnd();
  }               
  </code></pre>