我正在尋找一種方式來從外部命令行應用程序中按字節讀取標準輸出字節。C# - 從外部命令行應用程序中按字節讀取標準輸出字節
當前的代碼有效,但僅當添加換行符時才起作用。有沒有一種方法可以逐字節讀取當前行輸入字節,這樣我就可以更新用戶進度。
例)
Proccesing file 0% 10 20 30 40 50 60 70 80 90 100% |----|----|----|----|----|----|----|----|----|----| xxxxxx
一個X在控制檯應用程序每隔幾分鐘添加,但不是在我的C#贏形式,因爲它僅更新時,它已經完成了與當前行(結束)
示例代碼:
Process VSCmd = new Process();
VSCmd.StartInfo = new ProcessStartInfo("c:\\testapp.exe");
VSCmd.StartInfo.Arguments = "--action run"
VSCmd.StartInfo.RedirectStandardOutput = true;
VSCmd.StartInfo.RedirectStandardError = true;
VSCmd.StartInfo.UseShellExecute = false;
VSCmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
VSCmd.StartInfo.CreateNoWindow = true;
VSCmd.Start();
StreamReader sr = VSCmd.StandardOutput;
while ((s = sr.ReadLine()) != null)
{
strLog += s + "\r\n";
invoker.Invoke(updateCallback, new object[] { strLog });
}
VSCmd.WaitForExit();
感謝您的幫助! – RPS 2010-05-12 17:40:54