I'm currently trying to read the outputstream from an external console application. I can not modify this application.
This is to code i'm currently using:
        Process process = new Process();
        string dir = Directory.GetCurrentDirectory();
        process.StartInfo.FileName = dir + "/volibot.exe";
        process.StartInfo.UseShellExecute = false;
        process.Start();
        //do some stuff with the stream
I use this to read the outputstream:
            while (!process.StandardOutput.EndOfStream)
            {
                string message = process.StandardOutput.ReadLine();
                Console.WriteLine(message);
            }
But whenever I add:
        process.StartInfo.RedirectStandardOutput = true;
I get this error:
Unhandled exception: System.IO.IOException: The handle is invalid.
   bij System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   bij System.IO.__Error.WinIOError()
   bij System.Console.SetWindowSize(Int32 width, Int32 height)
   bij RitoBot.Core.Main(String[] args)
This doesn't make sense because this is a console application? How can I fix this problem? Or is there a simple work around?
Edit: Tried this: ProcessInfo and RedirectStandardOutput
    static void Main(string[] args)
    {
        //C:\\Users\\pc\\Documents\\Visual Studio 2013\\Projects\\ConsoleApplication1\\ConsoleApplication1\\bin\\Debug\\VoliBot.exe
        Process build = new Process();
        build.StartInfo.WorkingDirectory = @"C:\\Users\\pc\\Documents\\Visual Studio 2013\\Projects\\ConsoleApplication1\\ConsoleApplication1\\bin\\Debug\\";
        build.StartInfo.Arguments = "";
        build.StartInfo.FileName = "volibot.exe";
        build.StartInfo.UseShellExecute = false;
        build.StartInfo.RedirectStandardOutput = true;
        build.StartInfo.RedirectStandardError = true;
        build.StartInfo.CreateNoWindow = true;
        build.ErrorDataReceived += build_ErrorDataReceived;
        build.OutputDataReceived += build_ErrorDataReceived;
        build.EnableRaisingEvents = true;
        build.Start();
        build.BeginOutputReadLine();
        build.BeginErrorReadLine();
        build.WaitForExit();
        Console.ReadLine();
    }
    static void build_ErrorDataReceived(object sender, DataReceivedEventArgs e)
    {
        string strMessage = e.Data;
        Console.WriteLine(strMessage);
    } 
Still didnt work :s