本例講解了使用C#編程實(shí)現(xiàn)截取DOSming令返回值的實(shí)現(xiàn)方法。
tbResult.Text = "";
ProcessStartInfo start = new ProcessStartInfo("Ping.exe"); //設(shè)置運(yùn)行的ming令行文件問ping.exe文件,這個文件系統(tǒng)會自己找到
//如果是其它exe文件,則有可能需要指定詳細(xì)路徑,如運(yùn)行winRar.exe
start.Arguments = txtCommand.Text; //設(shè)置ming令參數(shù)
start.CreateNoWindow = true; //不顯示dosming令行窗口
start.RedirectStandardOutput = true; //
start.RedirectStandardInput = true; //
start.UseShellExecute = false; //是否指定操作系統(tǒng)外殼進(jìn)程啟動程序
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í)行完退出進(jìn)程
p.Close(); //關(guān)閉進(jìn)程
reader.Close(); //關(guān)閉流
新聞熱點(diǎn)
疑難解答
圖片精選