如何从 .NET 应用程序调用控制台应用程序并捕获控制台中生成的所有输出?
(请记住,我不想先将信息保存在文件中,然后重新列出,因为我希望实时接收它。)
使用以下命令可以很容易地实现这一点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();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)