Reputation: 12705
i am creating a process using System.DIagnostics.Process in c#
i have created a class CCProcess
inherited from the Process
class
the problem is that ErrorDataRecieved OR OutputDataReceived are not being fired..
herez my code
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);
}
};
}
what am i doing wrong?
the code provided is the constructor of the class CCProcess
Upvotes: 1
Views: 1046
Reputation: 12705
oooh i hate this.. posting question here and then answering them.. anyways
i was missing a bery basic thing
Process.BeginOutputReadLine()
wasted 2 hours because of this
more about this here
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.beginoutputreadline
Upvotes: 1