mirror of https://gitlab.com/basile.b/dexed.git
added TProcess utils to ce_common
This commit is contained in:
parent
83b568904c
commit
dd65981470
|
@ -9,7 +9,7 @@ uses
|
||||||
{$IFDEF WINDOWS}
|
{$IFDEF WINDOWS}
|
||||||
Windows,
|
Windows,
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
ActnList, dialogs, forms, process;
|
ActnList, dialogs, forms, process, asyncprocess;
|
||||||
|
|
||||||
const
|
const
|
||||||
DdiagFilter = 'D source|*.d|D interface|*.di|All files|*.*';
|
DdiagFilter = 'D source|*.d|D interface|*.di|All files|*.*';
|
||||||
|
@ -179,6 +179,16 @@ type
|
||||||
*)
|
*)
|
||||||
function exeInSysPath(anExeName: string): boolean;
|
function exeInSysPath(anExeName: string): boolean;
|
||||||
|
|
||||||
|
(**
|
||||||
|
* Clears then fills aList with aProcess output stream.
|
||||||
|
*)
|
||||||
|
procedure processOutputToStrings(const aProcess: TProcess; var aList: TStringList);
|
||||||
|
|
||||||
|
(**
|
||||||
|
* Terminates and frees aProcess;
|
||||||
|
*)
|
||||||
|
procedure killProcess(var aProcess: TAsyncProcess);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
// https://stackoverflow.com/questions/25438091/objectbinarytotext-error-with-a-treader-twriter-helper-class
|
// https://stackoverflow.com/questions/25438091/objectbinarytotext-error-with-a-treader-twriter-helper-class
|
||||||
|
@ -666,6 +676,42 @@ begin
|
||||||
exit(ExeSearch(anExeName, '') <> '');
|
exit(ExeSearch(anExeName, '') <> '');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure processOutputToStrings(const aProcess: TProcess; var aList: TStringList);
|
||||||
|
var
|
||||||
|
str: TMemoryStream;
|
||||||
|
sum: Integer;
|
||||||
|
cnt: Integer;
|
||||||
|
const
|
||||||
|
buffSz = 1024;
|
||||||
|
begin
|
||||||
|
if not (poUsePipes in aProcess.Options) then
|
||||||
|
exit;
|
||||||
|
//
|
||||||
|
sum := 0;
|
||||||
|
str := TMemoryStream.Create;
|
||||||
|
try
|
||||||
|
while aProcess.Output.NumBytesAvailable <> 0 do begin
|
||||||
|
str.Size := str.Size + buffSz;
|
||||||
|
cnt := aProcess.Output.Read((str.Memory + sum)^, buffSz);
|
||||||
|
sum += cnt;
|
||||||
|
end;
|
||||||
|
str.Size := sum;
|
||||||
|
aList.LoadFromStream(str);
|
||||||
|
finally
|
||||||
|
str.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure killProcess(var aProcess: TAsyncProcess);
|
||||||
|
begin
|
||||||
|
if aProcess = nil then
|
||||||
|
exit;
|
||||||
|
if aProcess.Running then
|
||||||
|
aProcess.Terminate(0);
|
||||||
|
aProcess.Free;
|
||||||
|
aProcess := nil;
|
||||||
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
RegisterClasses([TMRUList, TMRUFileList]);
|
RegisterClasses([TMRUList, TMRUFileList]);
|
||||||
DExtList := TStringList.Create;
|
DExtList := TStringList.Create;
|
||||||
|
|
Loading…
Reference in New Issue