On Sun, 20 Nov 2005, Michalis Kamburelis wrote:
> Andrew Haines wrote: > [...] > > > > I am not extremely familiar with how streams work, but using > > LoadFromStream(Output) may not "Read" the data so it can be replaced with > > new data. Also as I said I think S.LoadFromStream is blocking until the > > end of the stream is reached, which can't happen until the program has > > ended possibly resulting in lost data. Someone please correct me if I am > > wrong ;) > > > > That's a good point, S.LoadFromStream *should* be blocking but *currently it > isn't*. I reproduced Bobby's problem with TStringList.LoadFromStream (on > Linux, so it's not specific to Win32). Looking at implementation in > rtl/objpas/classes/stringl.inc, there's a test > Until BytesRead<>BufDelta > that should probably be changed to > Until BytesRead = 0 > > Then it should be possible to call S.LoadFromStream just once, and read the > whole output of a process. There should be no need to do the partial reads, > because TStringList.LoadFromStream should already handle this. Generally, > example "Reading large output" on > [http://wiki.lazarus.freepascal.org/index.php/Executing_External_Programs] > will not need to use memory stream anymore. One should just construct process > without poWaitOnExit (to prevent deadlock), and then be able to read it's > whole output using single call > AStringList.LoadFromStream(AProcess.Output); > > So right now I think that what Bobby is observing is a result of a bug in > FPC's implementation of TStringList.LoadFromStream. I'll try to fix it and > submit to FPC devels. I already have a fix in place. I'll test it and then commit. Regarding the TProcess output reading: There are 2 ways of doing it properly: 1. Execute the code 'as is' in a thread. 2. Use a loop to read it in small buffer, and check for availability of input (using select or it's equivalent on Windows), and call Application.ProcessMessages. Failing to do so, and using 'LoadFromStream' directly will make your program appear 'frozen' while it is reading (much as the lazarus compiler output does). The lazarus people could try implementing this for Lazarus, and put the needed code in the LCL ;-) Michael. _________________________________________________________________ To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe" as the Subject archives at http://www.lazarus.freepascal.org/mailarchives
