[Lazarus] Can't copy TMemoryStream to TProcess.Input

Michael Van Canneyt michael at freepascal.org
Sun Apr 7 15:54:40 CEST 2013



On Sun, 7 Apr 2013, Leonardo M. Ramé wrote:

> On 2013-04-07 10:54:12 +0200, Michael Van Canneyt wrote:
>>
>>
>> On Sat, 6 Apr 2013, Leonardo M. Ramé wrote:
>>
>>> On 2013-04-07 00:04:45 +0200, Michael Van Canneyt wrote:
>>>>
>>>>
>>>> On Sat, 6 Apr 2013, Leonardo M. Ramé wrote:
>>>>
>>>>> On 2013-04-06 13:22:39 -0300, Leonardo M. Ramé wrote:
>>>>>> On 2013-04-06 17:46:06 +0200, Mattias Gaertner wrote:
>>>>>>> On Sat, 6 Apr 2013 12:37:06 -0300
>>>>>>> Leonardo M. Ramé <l.rame at griensu.com> wrote:
>>>>>>>
>>>>>>>> [...]
>>>>>>>>> Check return value of Proc.Input.Write.
>>>>>>>>> And call Proc.CloseInput when your input was written completely.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>> Mmm, I'm getting the same result.
>>>>>>>>
>>>>>>>> I attached the new code.
>>>>>>>
>>>>>>> When you give Proc.Input.Write 200 bytes and it returns that the other
>>>>>>> process could only process 100 of them. What bytes do you have to write
>>>>>>> next?
>>>>>>>
>>>>>>
>>>>>> Sorry, I'm not getting it. Which other process?, apart from that,
>>>>>> Proc.Input.Write is always returning the sizeof(buffer) except when it
>>>>>> reaches the end, where it can be less than it.
>>>>>>
>>>>>> It seems that the Proc.Input part is ok, aparently the Proc.Output is
>>>>>> wrong :(
>>>>>>
>>>>>> I attached a slightly modified code.
>>>>>>
>>>>>
>>>>> Finally got it working, I was forgetting to read the last part of the
>>>>> Output stream. ...I still don't know why this last chunk of bytes
>>>>> doesn't show up in NumBytesAvailable.
>>>>
>>>> NumBytesAvailable is inherently unreliable. I didn't like it's addition.
>>>>
>>>> You should never use it in critical code.
>>>>
>>>> Michael.
>>>
>>> Maybe that's why the same program doesn't work on FreeBSD?. What can I
>>> use instead of it?.
>>
>> Read until the number of read bytes is zero.
>>
>
> This cannot be done, because when you don't have bytes available,
> Proc.Output.Read hangs.

Not if the process stops and closes it's output, then it should return with 
the last bytes in the buffer.

Michael.


More information about the Lazarus mailing list