Calling A Command Line Program From C#
Calling A Command Line Program From C#
Submitted by Corey Goldberg on Mon, 22/01/2007 - 17:03.I often need to call external command line programs from within my C# code. To do this, I use a Process object. Here is some example code I use for calling a Python program:

private void Execute()
{
Process proc = new Process();
proc.StartInfo.WorkingDirectory = @"C:\scripts";
proc.StartInfo.FileName = "python.exe";
proc.StartInfo.Arguments = "foo.py";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = false;
proc.StartInfo.RedirectStandardError = true;
proc.Start();
proc.WaitForExit();
proc.Close()
}
