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

Pierre Free Pascal pierre at freepascal.org
Wed Mar 25 10:47:30 CET 2015



> -----Message d'origine-----
> De : fpc-pascal-bounces at lists.freepascal.org [mailto:fpc-pascal-
> bounces at lists.freepascal.org] De la part de Michael Van Canneyt
> Envoyé : mercredi 25 mars 2015 09:54
> À : FPC-Pascal users discussions
> Objet : Re: [fpc-pascal] TProcess does not work in Windows XP
> 
> 
> 
> 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.

  It could also be due to the problem we detected in fpmkunit:
If the stderr is a separate pipe and that pipe is full,
the inferior will stop until that pipe is read.
See this patch:

http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/packages/fcl-process/src/
process.pp?r1=29107&r2=29303

  Could the difference between Windows 7 and Windows XP
be related to different amount to stderr pipe?
  Or maybe the internal pipe size is different?

In the hope this could be useful,

Pierre Muller



More information about the fpc-pascal mailing list