C#获得命令提示符输出

原文:http://blog.csdn.net/abrahu/article/details/6611504

C#获得命令提示符输出

分类: c#应用程序 600人阅读 评论(0) 收藏 举报
 C#中如何获得命令提示符cmd中的输出呢?我们知道我们可以使用Process类调用外部程序运行。

现在我们调用一个命令提示符,然后想获得它返回的文字该如何做呢。可以看下面的事例:

Process p = new Process();

p.StartInfo.CreateNoWindow = true;//不显示调用窗体界面

p.StartInfo.FileName = "InstallUtil.exe";//调用的程序

p.StartInfo.Arguments = "FileLogService.exe";//调用程序接受的参数

p.StartInfo.UseShellExecute = false;//这两个设置可以将输出内容返回

p.StartInfo.RedirectStandardOutput = true;//这两个设置可以将输出内容返回

bool b=p.Start();

StreamReader sr = p.StandardOutput;//将输出内容返回

string retInfo = sr.ReadToEnd();//获得字符串

原文地址:https://www.cnblogs.com/wishFreedom/p/3530223.html