Andrew Haines wrote:
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.
Anyway, for now: the method of example "Reading large output" in the
wiki still works OK. In other words: Bobby, for now you should use
memory streams to read the pipe, like presented on the wiki (and like
Andrew suggests). Then, after grabbing everything to TMemoryStream,
you can safely convert it to e.g. TStringList by
AStringList.LoadFromStream(AMemoryStream);
This Should Work :)
I think that TProcess.Output cannot be larger than a certain size on
some platforms, so this is why it is read in increments rather than
waiting until it is done. Because the program will stop until some
output is read to make room for new output.
Andrew
_________________________________________________________________
To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
archives at http://www.lazarus.freepascal.org/mailarchives
I already told you, the Lazarus Wiki example gives me the same results
like my code - 106kb and no byte more. I got the conclusion that the
Pipes are somehow limited to certain size of data.
As I can't go further with pipes (obviously), how can I execute external
app, and use the console's pipes to pipe the output?
Something like:
prog.exe [attr] > output.log
Executeprocess didn't allow me to do it. It just flashes a console for
the moment, and I have error from the debugger. No matter if I do it
with relative or fixed paths, executeprocess did not find the app.
_________________________________________________________________
To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
archives at http://www.lazarus.freepascal.org/mailarchives