I am trying to redirect the Console output of a C#/Mono application into a gtk# textview. There are zillions of answers here explaining how to redirect output of a command to whatever output device conceivable. However, I am trying to do the same on the current process. Originally the application was designed as command line, know I want a textview that displays all output. Here is what I have right now:
class Program
{
Main(string[] args)
{
Program prog = new Program();
Process proc = Process.GetCurrentProcess();
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.EnableRaisingEvents = true;
proc.ErrorDataReceived += prog.DataReceived;
proc.OutputDataReceived += prog.DataReceived;
proc.BeginErrorReadLine();
proc.BeginOutputReadLine();
}
void DataReceived(object sender, DataReceivedEventArgs e)
{
_MainWindow.SendData(e.Data);
}
}
Is this the right approach? Right now I am receiving the following exception when calling the BeginErrorReadLine()
method. The exception is just : Standard Error Can not be redirected
. I don't know if the problem is just the Process/Mono thing, or If I am just doing something wrong.