Reading Console Output

From Birnam Designs Wiki

Jump to: navigation, search

Reading the standard output from a console process that you have started in code:

  1. using System.Diagnostics;
  2. using System.IO;
  3. ProcessStartInfo pi = new ProcessStartInfo("cmd.exe", "/c dir");
  4. pi.WindowStyle = ProcessWindowStyle.Hidden;
  5. pi.RedirectStandardOutput = true;
  6. pi.UseShellExecute = false;
  7. Process p = Process.Start(pi);
  8. p.WaitForExit();
  9. p.Start();
  10. TextReader t = p.StandardOutput;
  11. MessageBox.Show(t.ReadToEnd());

thanks

Share This!
This page was last modified on 11 February 2010, at 19:43. This page has been accessed 387 times.