This example demonstrates how, from C #, to run an external program / application and read the output or results of this program.
The code below triggers the Windows command prompt ( cmd.exe
) and passes it the command that should be executed (in this case, the command dir
).
In the Arguments
property you can replace the dir command with the application of your interest (GFix with its parameters).
using System;
using System.Diagnostics;
public class RedirectingProcessOutput
{
public static void Main()
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/c dir *.cs";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Console.WriteLine("Output:");
Console.WriteLine(output);
}
}
This code has been copied from SO in English .