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";

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

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

Author: kyrathasoft

The only programmer in Glens Fork, Ky.