Is it possible to receive the output from System.Diagnostic.Process when..occur and not at the end of line ?
At the moment, i have
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
psi.UseShellExecute = false;
reg = System.Diagnostics.Process.Start(psi);
reg.OutputDataReceived += new DataReceivedEventHandler(SortOutputHandler);
reg.BeginOutputReadLine();
As you can see, a call to BeginOutputReadLine allow me to read the (redirected) output only when an end line is found.
Does exists the same method but that call the delegate “when the process send any char to output” ?
Thanks
It would seem that the asynchronous methods/events don’t allow you to read single characters from the output (Only complete lines, as the method names suggest).
The following code does what you want, but in a synchronous way:
The call to s.Read() seems to block the current thread (Even though there is a ReadBlock() version of it — the docwriter probably misunderstood), so you might want to make that in a seperate thread and do some message passing/eventraising of your own to make it asynchronous.
The program I tested with was a simple loop outputting integers from 0 to 10 with random intervals, without newlines in between, and calls to Console.Out.Flush for every write.