0

I am trying to display the output of a command-window in a textbox, but the code doesn't update. It only shows the first action, nothing more. What I want is it to update if new text appears in the commandline aswell.

Here is the code I have so far, which all get triggered on a button-click:

System.Diagnostics.ProcessStartInfo procStartInfo =
                 new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);

            procStartInfo.RedirectStandardOutput = true;
            procStartInfo.UseShellExecute = false;
            procStartInfo.CreateNoWindow = true;
            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            proc.StartInfo = procStartInfo;
            proc.Start();
            while (!proc.StandardOutput.EndOfStream)
            {
                string result = proc.StandardOutput.ReadToEnd();
                TextAreaOutput.AppendText(result + "\n");
            }

What am I missing?

David Moll
  • 117
  • 10
  • This is really the wrong way, but put Application.DoEvents() after the AppendText. – Ron Beyer Dec 31 '19 at 17:48
  • You can try to do that asynchronously, like in this thread [How to read to end process output asynchronously in C#?](https://stackoverflow.com/questions/9533070/how-to-read-to-end-process-output-asynchronously-in-c) – Pavel Anikhouski Dec 31 '19 at 17:52

0 Answers0