views:

1540

answers:

3

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".

+1  A: 

Check out this answer.

http://stackoverflow.com/questions/451228/how-to-send-input-to-the-console-as-if-the-user-is-typing/451986#451986

The idea is that you will receive the output received events when any is thrown after the process is started.

David Basarab
A: 

Hey I'm right now having the same problem. With my dummy app that just print out a number and then a newline every millisecond the event is risen for every output. But when trying to read from 3rd party app the output comes in chunks, just as you said. I've been googleing for some time now but no one but you have mentioned it. I'll comeback if manage to solve it.

joh
+1  A: 

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.

joh