Capturing all stdout data with Process.Start

I have a spawned process that spews about 3 MB / s on stdout. I want to capture all this data..NET Process.Start has a RedirectStandardOutput property that creates a FileStream object attached to the file descriptor stdout. It creates a FileStream with a buffer size of 4096 bytes. This is too bad for my needs. By the time I can start the background thread to read the redirected stdout, I already missed a few hundred kilobytes of data. Is there any way around this? Here is my code:

  var psi = new ProcessStartInfo { Arguments = CreateArgs(@"..."), CreateNoWindow = true, FileName = @"...", RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, WorkingDirectory = @"...", }; var process = new Process{StartInfo = psi, EnableRaisingEvents = true }; process.ErrorDataReceived += (sender, args) => Dispatcher.Invoke(() => _stderr.AppendText(args.Data)); // log this process.Start(); Task.Run(() => { var buffer = new byte[size]; using (var reader = new BinaryReader( ((FileStream)process.StandardOutput.BaseStream).)) { while (!process.HasExited) { reader.Read(buffer, 0, buffer.Length); ... 
+4
source share

All Articles