Capturing standard output from console app

Here's code that redirects output from my Proofreading Tracker console app:

using System;
using System.Diagnostics;

sealed class TestRedirStdOutput
{
    public static void Main()
    {
        Process p = new Process();
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.Arguments = "titles";
        p.StartInfo.FileName = "prt.exe";
        p.Start();

        // To avoid deadlocks, always read the output stream first and then wait.
        string output = p.StandardOutput.ReadToEnd();
        p.WaitForExit();

        Console.WriteLine(" Captured this output:\n");
        Console.WriteLine(output + "\n");
        Console.WriteLine(" Press any key to exit...");
        Console.ReadLine();
    }
}

Author: kyrathasoft

The only programmer in Glens Fork, Ky.