Skip to content

Commit

Permalink
* wait up to 10ms extra till process really done to get rest of input…
Browse files Browse the repository at this point in the history
…, closes #39821

 * avoid closing a popassinput handle.
  • Loading branch information
marcoonthegit committed Aug 8, 2022
1 parent a5486e0 commit d347487
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/fcl-process/src/pipes.pp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@
end;

TOutputPipeStream = Class(THandleStream)
private
FDontClose : boolean;
Public
destructor Destroy; override;
function Seek(const Offset: int64; Origin: TSeekOrigin): int64; override;
Function Read (Var Buffer; Count : Longint) : longint; Override;
property DontClose : boolean read FDontClose write FDontClose;
end;

Function CreatePipeHandles (Var Inhandle,OutHandle : THandle; APipeBufferSize : Cardinal = 1024) : Boolean;
Expand Down Expand Up @@ -126,7 +129,8 @@ function TInputPipeStream.Seek(const Offset: int64; Origin: TSeekOrigin): int64;

destructor TOutputPipeStream.Destroy;
begin
PipeClose (Handle);
if not fdontclose then
PipeClose (Handle);
inherited;
end;

Expand Down
5 changes: 5 additions & 0 deletions packages/fcl-process/src/win/process.inc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ end;
Function TProcessnamemacro.PeekExitStatus : Boolean;
begin
Result:=GetExitCodeProcess(ProcessHandle,FExitCode) and (FExitCode<>Still_Active);
// wait up to 10ms extra till process really done to get rest of input bug #39821
if not Result Then
WaitForSingleObject(FProcessHandle,10);
end;

Function GetStartupFlags (P : TProcessnamemacro): Cardinal;
Expand Down Expand Up @@ -296,6 +299,8 @@ Var
if Not (poStdErrToOutPut in Options) then
FileClose(FStartupInfo.hStdError);
CreateStreams(HI,HO,HE);
if poPassInput in Options then
FInputStream.DontClose:=true;
end;
end;
FRunning:=True;
Expand Down

0 comments on commit d347487

Please sign in to comment.