[英]Reading all output lines of a console application working from a win32 application using C#
我有一個 win32 應用程序,我使用以下代碼啟動一個控制台應用程序:
public void ExecuteDecript(int element)
{
string toquen = TaskList[element].MakeToquen();
string cmdexePath = @"C:\Windows\System32\cmd.exe";
string myApplication = @"d:/SL3-xgold/tools/oclHashcat-lite-0.05/" + toquen;
string cmdArguments = String.Format("/K {0}", myApplication);
OCLProcess = new Process();
OCLProcess.StartInfo.FileName = cmdexePath;
OCLProcess.StartInfo.Arguments = cmdArguments;
OCLProcess.StartInfo.UseShellExecute = false;
OCLProcess.StartInfo.RedirectStandardOutput = true;
OCLProcess.OutputDataReceived += OutputHandler;
OCLProcess.Start();
OCLProcess.BeginOutputReadLine();
}
private static void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
{
if (!String.IsNullOrEmpty(outLine.Data))
{
MessageBox.Show(outLine.Data);
}
}
問題是我讀取了控制台應用程序的所有行,但最后一行只有在我關閉控制台應用程序時才讀取。 有什么理論嗎?
上面的代碼應該可以正常運行。 但是,問題可能出在控制台應用程序上,可能在最后一次寫入時您執行Console.Write
而不是Console.WriteLine
,因此在應用程序終止並刷新 stream 之前不會讀取它。 如果這沒有幫助,請為您的控制台應用程序發布一些代碼以進一步診斷問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.