I am writing a C# application that can launch third party command line executables and redirect their standard output to a RichTextBox.
I am able to redirect the output alright by using the process.OutputDataReceived event. I have a queue that I push lines to, and then I use a timer to periodically dump all the queued lines into the RichTextBox.
This works perfectly for some third party programs.
The problem lies with programs that write to a single line of the console multiple times. eg: 5% -> 10% -> 25% etc... (constantly rewriting the same spot) This is done, I suppose, by not putting a line feed character, but rather simply returning to the beginning of the line with a carriage return and writing over the previous characters.
What happens is that the OutputDataReceived does not seem to have any way of indicating if a new line should be applied or not so my RichTextBox output simply has multiple updates on new lines. eg: 5% 10% 25% etc...
Is there any way to tell if the standard output is going on a new line or the same line?
Process.StandardOutput
is not a stream per se, but aTextReader
that decodes data from a stream. But yes, you can read from it directly; please see my answer posted below. – Peter Duniho