I've recently discovered the value of using existing console
applications in managed .net apps. Unfortunately, I've stumbled into a
problem with a particular console application that check's crc info on
CDs. Using either the StandardError or StandardOutput streams read,
readline or peek methods causes an immediate block that doesn't
release until the console app finishes it's business. I want to launch
this console app and update my UI to show it's still working. The read
methods currently get launched on another thread so the UI doesn't
freeze but either way the problem existed. If I run the executable
directly in the cmd.exe environment, I know that cmd.exe is working
interactively with the console application and kicking back the
results of the process. Any ideas or comments would be greatly
appreciated.
To sum up, I call read on either standarderror or standardoutput, I've
tried either stream first to make sure one wasn't filling up the
stream buffer and blocking the other. The read method blocks the
entire time the crc console application is running, probably 5
minutes. When the read method finally releases and my read loop can
iterate across the stream, I get the text that would normally display
at a command prompt interactively or as they occur.
Is this a bug in how the Process object interacts with the console
app?
I've used this model before where I read lines from the StandardOutput
stream as they occur when doing things like using dir /s c:\ and it
works fine. Or another application runs chkdsk and I get the 10%, 20%,
30% lines as they occur.
Some examples:
Process myProcess = new Process();
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(@"path to
exe" );
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardError = true;
myProcessStartInfo.RedirectStandardOutput = true;
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();
this .....>
ReaderThread oOut = new ReaderThread(myProcess.StandardOutput);
oOut.OutputLogFile = "OutLog.txt";
oOut.ReadComplete+=new
ISOTest.ReaderThread.ReadCompleteEventHandler(oOut _ReadComplete);
Thread tOut = new Thread(new ThreadStart(oOut.ReadOutput));
tOut.Start();
or this ....>
while (myProcess.StandartOutput.Peek() != -1)
{
myProcess.StandartOutput.Read(x, y, z);
or....>
myProcess.StandardOutput.ReadLine();
}
or any call(read, peek, readline) that attempts to read from the
stream. They all block
Thanks,
John