我有一个进程需要根据输出实时更新控制台。但它不起作用。控制台只是打开和关闭,进程在后台运行。我无法弄清楚我做错了什么。这是我的代码:
private static StringBuilder sortOutput = null;
static void Main(string[] args)
{
Process process;
process = new Process();
process.StartInfo.FileName = "C:\\ffmbc\\ffmbc.exe";
//process.StartInfo.Arguments = "-i new5830df.mxf -an ";
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
sortOutput = new StringBuilder("");
process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
process.Exited += new EventHandler(myProcess_Exited);
process.StartInfo.RedirectStandardInput = true;
process.Start();
process.BeginOutputReadLine();
}
private static void OutputHandler(object sender, DataReceivedEventArgs outLine)
{
string line;
line = (outLine.Data.ToString());
Console.WriteLine(line);
}
private static void myProcess_Exited(object sender, System.EventArgs e)
{
Console.WriteLine("Proccess Finished");
}