Is sleep is required before Process.StandardOutput.Read() method?
<p>I'm trying create a sub-process in C# program (cmd for example) and performing read/write with process IO streams. I'm using StandardOutput.Read() method to read process output. </p>

<p>When I put a Thread.Sleep() method before Read(), it gives complete output but if I remove it, it displays only single line of output.</p>

<p>Here is the code:</p>

<pre><code>string sProcess = "cmd.exe";
ProcessStartInfo psiInfo = new ProcessStartInfo();
psiInfo.FileName = sProcess;
psiInfo.CreateNoWindow = true;
psiInfo.UseShellExecute = false;
psiInfo.RedirectStandardOutput = true;
psiInfo.RedirectStandardError = true;
psiInfo.RedirectStandardInput = true;
Process pChild = new Process();
pChild.StartInfo = psiInfo;
if (pChild.Start())
{
    int ch;
    do
    {
        Thread.Sleep(50);
        ch = pChild.StandardOutput.Peek();
        if (ch &gt; 0)
            Console.Write((char)pChild.StandardOutput.Read());
    } while (ch &gt; 0);
    Console.WriteLine("exit");
    pChild.StandardInput.WriteLine("exit");
}
</code></pre>

<p><em>Output with Sleep enabled:</em></p>

<pre>
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved. 

D:\ProcessDemo_001\bin\Release>exit 
</pre>

<p><em>Output with Sleep disabled:</em></p>

<pre>
Microsoft Windows [Version 6.1.7601]exit
</pre>

<p>I want to know why this happens?</p>
