I am spawning external console application and use async output redirect.
as shown in this SO post
My problem is it seems that the spawned process needs to produce certain amount of output before I get the OutputDataReceived event notification.
I want to receive the OutputDataReceived event as soon as possible.
I have a bare-bones redirecting application, and here are some observations:
1. When I call a simple 'while(true) print("X");' console application (C#) I receive output event immediately.
2. When I call a 3d party app I am trying to wrap from the command line I see the line-by-line output.
3. When I call that 3d party app from my bare-bone wrapper (see 1) - the output comes in chunks (about one page size).
What happens inside that app?
FYI: The app in question is a "USBee DX Data Exctarctor (Async bus) v1.0".
I did some more research and have a fix to microsofts Process class. But as my last answer was deleted without a reason, I have had to create a new one.
So take this example...
Create a windows app and stick a rich textbox on the main form, then add this to the form load...
This will output something like this...
The OutputDataReceived event is not fired for the last line. After some ILSpying it appears that this is deliberate because the last line does not end with a crlf, it assumes there is more comming and appends it to the start of the next event.
To correct this, I have written a wrapper for the Process class and taken some of the required internal classes out with it so that it all works neatly. Here is the FixedProcess class...
Stick that in your project and then change ...
to
Now your application should display something like this...
without needing to make any other changes to your existing code. It is also still async and wrapped up nicely. The one caveat is that now you will get multiple events for large output with potential breaks in-between, so you will need to handle this scenario yourself. Other than that, it should be all good.
Check out this answer.
How to send input to the console as if the user is typing?
The idea is that you will receive the output received events when any is thrown after the process is started.
It seems as the problem was that the dummy app was written in c# which flushes the output automatically one every println while the 3rd party app was written in c/c++ and therefore only wrote when the stdoutbuffer was full. The only solution which ive found is to make sure the c/c++ app flushes after every print or to set its buffer to 0.