Hello,
I need to asynchronously read the stdout stream of a processcharacter-at-a-time, even if there is no newline character. My simplified but still failing code is below. I realize there is an infinite loop in it but that is not the issue. This code reads the characters fine until all of them have been read, but when it then goes back for another character it never returns. I've tried using Peek before I do the read and for some of my processes this fixes the problem. However, for others Peek hangs too. I've tried using the debugger to step into Read and Peek but nothing happens. My processes are nothing more than simple "Hello world" C and C++ console applications that also do a little inputting from stdin. Is it possible that if a process is paused and waiting for input from stdin Read and Peek will hang? I'm using Win 8.1 Pro 64-bit, VS2013 Ultimate, and building for .NET 4.5.
Thanks,
Ray
publicstaticvoidRunIt(){Process process =newProcess();
process.StartInfo.FileName="D:\\temp\\C1A7E1.exe";
process.StartInfo.UseShellExecute=false;
process.StartInfo.RedirectStandardOutput=true;
process.StartInfo.RedirectStandardError=true;
process.StartInfo.RedirectStandardInput=true;
process.StartInfo.CreateNoWindow=true;
process.Start();string textString =string.Empty;for(;;){int outputCharInt;if((outputCharInt = process.StandardOutput.Read())!=-1)
textString +=(char)outputCharInt;elseThread.Sleep(1000);}}