Delay reading output from a process

BlitzMax Forums/BlitzMax Programming/Delay reading output from a process

JoshK(Posted 2011) [#1]
I have a BlitzMax program that launches a C++ process and prints the output read from the C++ program. It works fine, except that the C++ program's output isn't displayed until it ends! If the C++ program prints a line, it won't be shown by the BlitzMax program until the C++ program completes. I have experienced the same with two BlitzMax programs as well.

The C++ program is a Win32 project, not a Win32 console project. Not sure whether that will make a difference.

Here is my code for reading the output of the C++ program:
	Method ReadProcess:String()
		Local s:String
		Local keeplooping:Int
		Local l:String
		
		Repeat
			keeplooping=False
			
			If Process.pipe.ReadAvail()>0
				l=process.pipe.ReadString(process.pipe.ReadAvail())
				If l s:+l
				keeplooping=True
			EndIf	
			
			If Process.err.ReadAvail()>0
				l=process.err.ReadString(process.err.ReadAvail())
				If l s:+l
				keeplooping=True
			EndIf	
			
			If Not keeplooping Exit
		Forever
		Return s
	EndMethod

Has anyone experienced this, and do you know how to fix it?

Last edited 2011


skidracer(Posted 2011) [#2]
Is your c++ code calling flush after every write?


JoshK(Posted 2011) [#3]
I am now. :)

Incidentally, each of my printf calls did end with "\n" but apparently the call to fflush(stdout); is needed.

Thanks!


col(Posted 2011) [#4]
Hiya,

@JoshK
I did have the same effect, but I didnt know the correct solution.

Thankyou skidracer