本例講解了使用C#編程實現截取DOSming令返回值的實現方法。
tbResult.Text = "";
ProcessStartInfo start = new ProcessStartInfo("Ping.exe"); //設置運行的ming令行文件問ping.exe文件,這個文件系統會自己找到
//如果是其它exe文件,則有可能需要指定詳細路徑,如運行winRar.exe
start.Arguments = txtCommand.Text; //設置ming令參數
start.CreateNoWindow = true; //不顯示dosming令行窗口
start.RedirectStandardOutput = true; //
start.RedirectStandardInput = true; //
start.UseShellExecute = false; //是否指定操作系統外殼進程啟動程序
Process p=Process.Start(start);
StreamReader reader = p.StandardOutput; //截取輸出流
string line = reader.ReadLine(); //每次讀取一行
while (!reader.EndOfStream)
{
tbResult.AppendText(line+" ");
line = reader.ReadLine();
}
p.WaitForExit(); //等待程序執行完退出進程
p.Close(); //關閉進程
reader.Close(); //關閉流
新聞熱點
疑難解答
圖片精選