[fpc-pascal] TProcess does not work in Windows XP

Michael Van Canneyt michael at freepascal.org
Wed Mar 25 09:54:05 CET 2015



On Wed, 25 Mar 2015, Antonio Sanguigni wrote:

> 2015-03-25 8:41 GMT+01:00 Michael Van Canneyt <michael at freepascal.org>:
>>> ---------------------- code ---------------
>>> procedure TBurpClient.Run;
>>> begin
>>>  fOurProcess.Options := [poUsePipes] + [poNoConsole];
>>>  fOurProcess.Execute;
>>>  while True do
>>>  begin
>>>    // make sure we have room
>>>    fMemStream.SetSize(fBytesRead + READ_BYTES);
>>>
>>>    // try reading it
>>>    fNumBytes := fOurProcess.Output.Read((fMemStream.Memory +
>>> fBytesRead)^, READ_BYTES);
>>>    if fNumBytes > 0 then // All read() calls will block, except the final
>>> one.
>>
>>
>> I am not sure this is always correct. Various versions of windows work
>> differently in this regard;
>> zero (0) may be a valid return value. I suggest you check
>> fOurProcess.IsRunning to break the loop.
>
> Thank you, I will try it. But debugging I can see the problem is not
> in the loop. In Windows XP fNumBytes is always zero:
>
> fNumBytes := fOurProcess.Output.Read((fMemStream.Memory +
> fBytesRead)^, READ_BYTES);
>
> so it seems the Read of fOurProcess.Output is not giving the expected results.

Read translates directly to a kernel call.

>
> In Windows 7 it's ok.

Once more:
Zero is a valid return value for read from a pipe.

So it can perfectly be that read attempts 50 times returns 0, and only at 
read attempt 51 you get a positive result.

That is why you must check isRunning, and not rely on the return value of readbytes.

Michael.



More information about the fpc-pascal mailing list