title: Execute long time command in SSH.NET and display the results continuously in TextBox
body: <p>Is there any way to execute Linux command and display the result in text box in Windows application like PuTTY.</p>
  
  <p>For example I'm trying to execute the following commands </p>
  
  <pre><code>wget http://centos-webpanel.com/cwp-latest
  sh cwp-latest
  </code></pre>
  
  <p>using the following code </p>
  
  <pre><code>SshClient sshclient = new SshClient(IPtxtBox.Text, UserNameTxt.Text, PasswordTxt.Text);
  sshclient.Connect();
  ShellStream stream = sshclient.CreateShellStream("customCommand", 80, 24, 800, 600, 1024);
  
  resultTxt.Text = SSHCommand.SendCommand(stream, "wget http://centos-webpanel.com/cwp-latest &amp;&amp; sh cwp-latest");
  </code></pre>
  
  
  
  <pre><code>private static void WriteStream(string cmd, StreamWriter writer, ShellStream stream)
  {
      writer.WriteLine(cmd);
      while (stream.Length == 0)
          Thread.Sleep(500);
  }
  private static string ReadStream(StreamReader reader)
  {
      StringBuilder result = new StringBuilder();
  
      string line;
      while ((line = reader.ReadLine()) != null)
          result.AppendLine(line);
  
      return result.ToString();
  }
  private static string SendCommand(ShellStream stream, string customCMD)
  {
      StringBuilder strAnswer = new StringBuilder();
  
      var reader = new StreamReader(stream);
      var writer = new StreamWriter(stream);
      writer.AutoFlush = true;
      WriteStream(customCMD, writer, stream);
  
      strAnswer.AppendLine(ReadStream(reader));
  
      string answer = strAnswer.ToString();
      return answer.Trim();
  }
  </code></pre>
  
  <p>This command takes along time to be executed and no result appeared on the result text box.</p>