1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| procedure TForm1.GetProcess(LstResult:TStringList);
const
BUF_SIZE = 2048;
var
AProcess : TProcess;
OutputStream : TStream;
BytesRead : longint;
Buffer : array[1..BUF_SIZE] of byte;
begin
LstResult.Clear;
AProcess := TProcess.Create(nil);
AProcess.Executable := '/bin/ps';
AProcess.Parameters.Add('-aU');
AProcess.Parameters.Add(User_Name);
AProcess.Options := [poUsePipes];
AProcess.Execute;
OutputStream := TMemoryStream.Create;
repeat
BytesRead := AProcess.Output.Read(Buffer, BUF_SIZE);
OutputStream.Write(Buffer, BytesRead)
until BytesRead = 0;
AProcess.Terminate(0);
AProcess.Free;
OutputStream.Position := 0;
LstResult.LoadFromStream(OutputStream);
OutputStream.Free;
end; |
Partager