HOW TO:在C#中执行命令行,得到性病OUT的结果 [英] How To: Execute command line in C#, get STD OUT results
本文介绍了HOW TO:在C#中执行命令行,得到性病OUT的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何执行从C#中的命令行程序和取回性病OUT的结果。具体来说,我想在以编程方式选择两个文件执行DIFF和结果写入一个文本框。是的,我可以想出解决办法为自己,但肯定别人做类似的东西,我懒...
解决方案
//启动子进程。
进程p =新的Process();
//重定向子进程的输出流。
p.StartInfo.UseShellExecute = FALSE;
p.StartInfo.RedirectStandardOutput = TRUE;
p.StartInfo.FileName =YOURBATCHFILE.bat;
p.Start();
//不要等到子进程之前退出
//读取其重定向流的末尾。
// p.WaitForExit();
//首先读取输出流,然后等待。
字符串输出= p.StandardOutput.ReadToEnd();
p.WaitForExit();
code是<一个href=\"http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx\">MSDN.
How do I execute a command-line program from C# and get back the STD OUT results. Specifically, I want to execute DIFF on two files that are programmatically selected and write the results to a text box. Yes, I could figure this out for myself, but surely someone else has done something like it and I'm lazy...
解决方案
// 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();
Code is from MSDN.
这篇关于HOW TO:在C#中执行命令行,得到性病OUT的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文