Redirecting command window messages to rich text box

  • Thread starter Thread starter Pillasaar
  • Start date Start date
P

Pillasaar

Guest
Hello All,

I am trying to run a batch script from my C# desktop application.

I want to display all errors and messages from command prompt to be redirected to a rich text box. Now, I want these messages to be displayed the same time as it is output - not to display all the messages after the batch script has finished running. This is what I did:


private void button1_Click(object sender, EventArgs e)
{
// Start the child process.
Process p = new Process();

// Redirect the output stream of the child process.
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;


p.StartInfo.FileName = "batchScript.bat";
p.StartInfo.Arguments = string.Format("\"{0}\" \"{1}\"", arg1, arg2);

p.Start();

string text = p.StandardOutput.ReadToEnd();
richTextBox1.Text = text;

p.WaitForExit();
}


But my code only outputs all the messages to the text box when the batch script has finished executing. How do I make it printout the messages instantly?

I rarely uses C# and .Net and do not know about the topic at hand in depth.

Regards,

Sudhi

Continue reading...
 

Similar threads

Back
Top