Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I redirect process output (console) to richtextbox?
    primarykey
    data
    text
    <p>what is wrong why is that the richtextbox doesnt get the stream of Process output? theres no text display in richtextbox..</p> <pre><code> private void button1_Click(object sender, EventArgs e) { Process sortProcess; sortProcess = new Process(); sortProcess.StartInfo.FileName = "sort.exe"; sortProcess.StartInfo.Arguments = this.comboBox1.SelectedItem.ToString(); // Set UseShellExecute to false for redirection. sortProcess.StartInfo.CreateNoWindow = true; sortProcess.StartInfo.UseShellExecute = false; // Redirect the standard output of the sort command. // This stream is read asynchronously using an event handler. sortProcess.StartInfo.RedirectStandardOutput = true; sortOutput = new StringBuilder(""); // Set our event handler to asynchronously read the sort output. sortProcess.OutputDataReceived += new DataReceivedEventHandler(SortOutputHandler); // Redirect standard input as well. This stream // is used synchronously. sortProcess.StartInfo.RedirectStandardInput = true; // Start the process. sortProcess.Start(); // Start the asynchronous read of the sort output stream. sortProcess.BeginOutputReadLine(); sortProcess.WaitForExit(); richTextBox1.AppendText(sortOutput.ToString()); } private static void SortOutputHandler(object sendingProcess, DataReceivedEventArgs outLine) { sortOutput.Append(Environment.NewLine + "[" + numOutputLines.ToString() + "] - " + outLine.Data); } } </code></pre> <p>so when sort.exe launches, it displays text, i want all those text be displayed also in richtextbox in RealTime (i dont want to wait for the process to exit, and then read all output)</p> <p>how can i do it? any wrong part of my code? thanks</p> <p>UPDATE @botz</p> <p>i added this in my code</p> <pre><code> private void SortOutputHandler(object sendingProcess, DataReceivedEventArgs outLine) { sortOutput.Append(Environment.NewLine + "[" + numOutputLines.ToString() + "] - " + outLine.Data); richTextBox1.AppendText(sortOutput.ToString()); } </code></pre> <p>but it throws this exception </p> <pre><code>Cross-thread operation not valid: Control 'richTextBox1' accessed from a thread other than the thread it was created on. </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload