1

我正在使用 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

4

1 回答 1

1

哦,我讨厌这个..在这里发布问题然后回答他们..无论如何
我错过了一个基本的东西
Process.BeginOutputReadLine()
浪费了2个小时,因为这里有更多关于这个
http://msdn.microsoft.com/en-us/library/system .diagnostics.process.beginoutputreadline

于 2012-06-26T20:37:18.760 回答