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