如何从 C# 执行命令行程序并取回 STD OUT 结果?具体来说,我想对以编程方式选择的两个文件执行 DIFF,并将结果写入文本框。
最佳答案
// 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 .
关于c# - 如何 : Execute command line in C#, 获取 STD OUT 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/206323/