我正在使用c#
中的System.DIagnostics.Process创建一个进程
我创建了一个继承自CCProcess
类的班级Process
问题是没有触发ErrorDataRecieved OR OutputDataReceived ..
在这里我的代码
public CCProcess(string executablePath, string[] parameters, CCProcessInfo processInfo)
{
this.ProcessInfo = processInfo;
this.OutputMessages = new List<ProcessOutputMessage>();
this.ProcessId = Guid.NewGuid().ToString();
base.EnableRaisingEvents = true;
this.StartInfo = new ProcessStartInfo(executablePath)
{
Arguments = string.Join(" ", parameters.Select(s => string.Format("\"{0}\"", s))),
CreateNoWindow = true,
ErrorDialog = false,
RedirectStandardError = true,
RedirectStandardInput = true,
RedirectStandardOutput = true,
StandardErrorEncoding = Encoding.UTF8,
StandardOutputEncoding = Encoding.UTF8,
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false
};
this.ErrorDataReceived += (sender, e) =>
{
this.OutputMessages.Add(new ProcessOutputMessage() { Message = e.Data, Type = OutputType.Error });
if (this.ErrorData_Recieved != null&&!string.IsNullOrEmpty(e.Data))
{
this.ProcessInfo.LastResponseFromProcess = DateTime.Now;
this.ErrorData_Recieved(e.Data);
}
};
this.OutputDataReceived += (sender, e) =>
{
this.OutputMessages.Add(new ProcessOutputMessage() { Message = e.Data, Type = OutputType.Output });
if (OutputData_Recieved != null && !string.IsNullOrEmpty(e.Data))
{
this.ProcessInfo.LastResponseFromProcess = DateTime.Now;
OutputData_Recieved(e.Data);
}
};
}
我做错了什么?CCProcess
的构造函数
答案 0 :(得分:0)
哦,我讨厌这个......发布问题然后回答他们..反正道
我错过了一个基本的东西
Process.BeginOutputReadLine()
因为这个浪费了2个小时
更多关于这一点
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.beginoutputreadline