Forum > General

wiki.freepascal.org/Executing_External_Programs

(1/1)

xint:
Hello,

I followed the example given on the webpage in subject. Since the external program I start returns a lot of data, I needed to use the example 'Reading large output'.
Everything functions well. The program starts, the output is being captured, but once the program exits and my application is emtying the pipe, I get lots or trash at the end of the captured data. It seems, that I read a lot of crap from the uninitialized buffer which is permanently attached to the end of the memorystream !?
Any advice how to fix this issue ?

Thanks a million !

dsiders:

--- Quote from: xint on December 18, 2018, 07:40:25 pm ---I followed the example given on the webpage in subject. Since the external program I start returns a lot of data, I needed to use the example 'Reading large output'.

Everything functions well. The program starts, the output is being captured, but once the program exits and my application is emtying the pipe, I get lots or trash at the end of the captured data. It seems, that I read a lot of crap from the uninitialized buffer which is permanently attached to the end of the memorystream !?

Any advice how to fix this issue ?

--- End quote ---

Use the FillByte or FillChar procedure to initialize the buffer.

https://www.freepascal.org/docs-html/rtl/system/fillbyte.html
https://www.freepascal.org/docs-html/rtl/system/fillchar.html

xint:
Thanks, but that doesn't help much. The sample code re-alocates the buffer while it partially contains valid data already.
Furthermore, This would just replace the crap characters by whitespace - the file would still consist of lots of additional characters.

xint:
My apologies. In my original post, I refered to the German wiki, but changed the link to the English one here in my post.
The German version describes a different approach to the problem. Will look over the English version now.

marcov:
Or look at the source for the various RunCommand helper procedures that wrap TProcess. Preferably in trunk:-)

Navigation

[0] Message Index

Go to full version