<p>I have the following code:</p>
<pre><code>info = new System.Diagnostics.ProcessStartInfo(&quot;TheProgram.exe&quot;, String.Join(&quot; &quot;, args));
info.CreateNoWindow = true;
info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
System.Diagnostics.Process p = System.Diagnostics.Process.Start(info);
p.WaitForExit();
Console.WriteLine(p.StandardOutput.ReadToEnd()); //need the StandardOutput contents
</code></pre>
<p>I know that the output from the process I am starting is around 7MB long. Running it in the Windows console works fine. Unfortunately programmatically this hangs indefinitely at <code>WaitForExit</code>. Note also this code does NOT hang for smaller outputs (like 3KB).</p>
<p>Is it possible that the internal <code>StandardOutput</code> in <code>ProcessStartInfo</code> can't buffer 7MB? If so, what should I do instead? If not, what am I doing wrong?</p>

The
documentation
for
```
Process.StandardOutput
```
says to read before you wait otherwise you can deadlock, snippet copied below:
```
```
// 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();
 // Do not wait for the child process to exit before
 // reading to the end of its redirected stream.
 // p.WaitForExit();
 // Read the output stream first and then wait.
 string output = p.StandardOutput.ReadToEnd();
 p.WaitForExit();
```
```