Capture console output in C#

- Posted in Coding by

The following C# source code demonstrates how to capture the output of a console program:

How to capture output from a process using c-sharp

- Posted in Uncategorized by

C# Capturing output from a process

namespace LaunchAndCaptureOutput{

    class Lacout{
    static void Main(){

        var proc = new Process{
                StartInfo = new ProcessStartInfo{
                    FileName = @"C:csdevlessonslessonette7hello.exe",
                    UseShellExecute = false,
                    RedirectStandardOutput = true,
                    CreateNoWindow = true
                }
        };

        proc.Start();
        string p = proc.StandardOutput.ReadToEnd();
        proc.WaitForExit();
        Console.WriteLine("Captured output: " + p);
      }
    }

}