c# - 如何 : Execute command line in C#, 获取 STD OUT 结果

标签 c# command-line

如何从 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/

相关文章:

c# - 在mysql中使用scope_identity()、@@identity()、last_insert_id()的正确版本是什么

c# - IEnumerable 和 Array、IList 和 List 有什么区别?

c# - C# 中的线程上下文到底是什么?

command-line - 如何在 vb6 中运行命令行?

ruby - 从命令行调用 Ruby 方法

shell - 脚本中从远程主机到本地服务器的 scp

C# Http.Response 流返回内容类型为 application/json 的空字符串

c# - 无法激活 Windows 应用商店应用程序(Visual Studio 2015,Windows 10 版本 1511)

command-line - PSEXEC - "The Handle is invalid"以系统用户身份运行命令时

command-line - 在没有工作空间的情况下将文件 checkin TFS(命令行)