本文共 1082 字,大约阅读时间需要 3 分钟。
导读:
这个问题来自论坛提问,答案如下.这只是一个简单的ipconfig命令.如果是复杂的,比如oracle的exp之类的命令,能在调用的时候显示出来,还是相当酷的.
using System;
using System.Windows.Forms;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
namespace WindowsApplication8![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
... {
public partial class Form1 : Form![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
public Form1()![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
InitializeComponent();
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
delegate void dReadLine(string strLine);
private void excuteCommand(string strFile, string args, dReadLine onReadLine)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = new System.Diagnostics.ProcessStartInfo();
p.StartInfo.FileName = strFile;
p.StartInfo.Arguments = args;
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.Start();
System.IO.StreamReader reader = p.StandardOutput;//截取输出流
string line = reader.ReadLine();//每次读取一行
while (!reader.EndOfStream)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
onReadLine(line);
line = reader.ReadLine();
}
p.WaitForExit();
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private void button1_Click(object sender, EventArgs e)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
excuteCommand("ipconfig", "", new dReadLine(PrintMessage));
}
private 本文转自
转载地址:http://ygnob.baihongyu.com/