I have a spawned process that spews about 3MB/second to stdout. I want to capture all of this data. The .NET Process.Start
has the RedirectStandardOutput
property that creates a FileStream
object attached to the stdout file handle. It creates that FileStream
with a 4096 byte buffer size. It's too puny for my needs. By the time I can start the background thread to read the redirected stdout, I've already missed several 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);
...