一尘不染

如何:在C#中执行命令行,获取STD OUT结果

c#

如何从C#执行命令行程序并获取STD OUT结果?具体来说,我想在以编程方式选择的两个文件上执行DIFF,并将结果写入文本框。


阅读 248

收藏
2020-05-19

共1个答案

一尘不染

// Start the child process.
 Process p = new Process();
 // Redirect the output stream of the child process.
 p.StartInfo.UseShellExecute = false;
 p.StartInfo.RedirectStandardOutput = true;
 p.StartInfo.FileName = "YOURBATCHFILE.bat";
 p.Start();
 // Do not wait for the child process to exit before
 // reading to the end of its redirected stream.
 // p.WaitForExit();
 // Read the output stream first and then wait.
 string output = p.StandardOutput.ReadToEnd();
 p.WaitForExit();

代码来自MSDN

2020-05-19