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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
program ReadOutput;
{$APPTYPE CONSOLE}
uses
Libc,
Classes,
SysUtils;
const BufferSize = 1024;
var
Output: PIOFile;
Line: PChar;
CountRead: Cardinal;
S: String;
Results: TStringList;
I: Integer;
begin
Output := Libc.popen('ls -l /', 'r');
if Output = nil then
begin
Writeln('Error Popen');
Exit;
end;
try
S := '';
GetMem(Line, BufferSize + 1);
try
while Libc.feof(Output) = 0 do
begin
CountRead := Libc.fread(Line, 1, BufferSize, Output);
Line[CountRead] := #0;
S := S + Line;
end;
finally
FreeMem(Line);
end;
finally
Libc.pclose(Output);
Libc.Wait(nil);
end;
Results := TStringList.Create;
try
Results.Text := S;
for I := 0 to Results.Count - 1 do
Writeln(Results[I]);
finally
Results.Free;
end;
end. |
Partager