How to read standard output without leaking memory? The p.StandardOutput.ReadToEnd(); is a wrong choice on large output because it allocates a large number of chars in SOH.
// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "Write500Lines.exe";
p.Start();
**string output = p.StandardOutput.ReadToEnd();**
p.WaitForExit();
Process.StandardOutput is a
StreamReader, and you can read the content line by line to save memory: