DOS exe output?

  • Thread starter Thread starter AxOn
  • Start date Start date
A

AxOn

Hi, I have a small dos program that compiles txt files. The dos program
checks the text file, and if there's an error or if the text is ok it
sends a message to the dos prompt. I would like to capture this message
and display it in a textbox. I have already tried with the code below,
but i don't get the output from the text compler program, but I do get
some DOS output like the path the program is in etc. Does anybody know
how to solve this problem????

System.Diagnostics.Process p2 = new System.Diagnostics.Process();
StreamWriter sw2;
StreamReader sr2;
StreamReader err2;
System.Diagnostics.ProcessStartInfo psI2 = new
System.Diagnostics.ProcessStartInfo("POINT");
psI2.UseShellExecute = false;
psI2.RedirectStandardInput = true;
psI2.RedirectStandardOutput = true;
psI2.RedirectStandardError = true;
psI2.CreateNoWindow = true;
psI2.Arguments = "/K" + compileTextFile;
p2.StartInfo = psI2;


p2.Start();
sw2 = p2.StandardInput;
sr2 = p2.StandardOutput;
err2 = p2.StandardError;
textBox1.Text = sr2;

Thanks!
 
AxOn said:
Hi, I have a small dos program that compiles txt files. The dos program
checks the text file, and if there's an error or if the text is ok it
sends a message to the dos prompt. I would like to capture this message
and display it in a textbox. I have already tried with the code below,
but i don't get the output from the text compler program, but I do get
some DOS output like the path the program is in etc. Does anybody know
how to solve this problem????

You can't just assign the Text property of a TextBox to be a
StreamReader. Instead, you need to read from stdout/stderr, and take
appropriate action when you read something. Note that in order to avoid
deadlocks where the process runs out of output buffering, it's worth
doing the reading on different threads. (As always, make sure that the
bit of code which updates the UI uses Control.Invoke/BeginInvoke to get
to the UI thread.)

Jon
 
Back
Top