Recent

Author Topic: wiki.freepascal.org/Executing_External_Programs  (Read 2072 times)

xint

  • Newbie
  • Posts: 3
wiki.freepascal.org/Executing_External_Programs
« on: December 18, 2018, 07:40:25 pm »
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

  • Hero Member
  • *****
  • Posts: 1052
Re: wiki.freepascal.org/Executing_External_Programs
« Reply #1 on: December 18, 2018, 08:05: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 ?

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
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

xint

  • Newbie
  • Posts: 3
Re: wiki.freepascal.org/Executing_External_Programs
« Reply #2 on: December 19, 2018, 06:39:33 am »
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

  • Newbie
  • Posts: 3
Re: wiki.freepascal.org/Executing_External_Programs
« Reply #3 on: December 19, 2018, 06:51:35 am »
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

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: wiki.freepascal.org/Executing_External_Programs
« Reply #4 on: December 19, 2018, 08:29:54 am »
Or look at the source for the various RunCommand helper procedures that wrap TProcess. Preferably in trunk:-)

 

TinyPortal © 2005-2018