使用ProcessStartInfo.RedirectStandardOutput属性可以很容易地实现这一点。完整的示例包含在链接的MSDN文档中。唯一的警告是,您可能还必须重定向标准错误流,才能查看应用程序的所有输出。
Process compiler = new Process();compiler.StartInfo.FileName = "csc.exe";compiler.StartInfo.Arguments = "/r:System.dll /out:sample.exe stdstr.cs";compiler.StartInfo.UseShellExecute = false;compiler.StartInfo.RedirectStandardOutput = true;compiler.Start();Console.WriteLine(compiler.StandardOutput.ReadToEnd());compiler.WaitForExit();



