我试过这个
myProcess = new Process();
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
myProcess.StartInfo.FileName = "Hello.exe";
myProcess.StartInfo.Arguments ="-say Hello";
myProcess.StartInfo.UseShellExecute = false;
myProcess.OutputDataReceived += new DataReceivedEventHandler(myProcess_OutputDataReceived);
myProcess.ErrorDataReceived += new DataReceivedEventHandler(myProcess_OutputDataReceived);
myProcess.Exited += new EventHandler(myProcess_Exited);
myProcess.EnableRaisingEvents = true;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.RedirectStandardError = true;
myProcess.StartInfo.ErrorDialog = true;
myProcess.StartInfo.WorkingDirectory = "D:\\Program Files\\Hello";
myProcess.Start();
myProcess.BeginOutputReadLine();
myProcess.BeginErrorReadLine();
然后我收到此错误.. alt text http://img188.imageshack.us/img188/3759/errorstack.jpg
我的过程需要很长时间才能完成,所以我需要在运行时显示进度。
答案 0 :(得分:3)
您无需调用ReadLine()
,读取的文本行是DataReceivedEventArgs
对象中传递给您的属性之一。