[Lazarus] Run 3 extrenal program, pipeline
Sven Barth
pascaldragon at googlemail.com
Fri Feb 3 11:15:26 CET 2012
Am 02.02.2012 12:00, schrieb xmldom at seznam.cz:
> Hi, I need run 3 external program and redirected output: first | second | third
>
> For example:
> df -hT | grep -v -E 'tmpfs|ecryptfs' | grep 'sda2'
> it gives
> /dev/sda2 ext4 19G 11G 7,6G 58% /
>
> I use this http://wiki.lazarus.freepascal.org/Executing_External_Programs#How_to_redirect_output_with_TProcess sample code. It works fine for first | second.
Completely different solution: Why do you need to run three processes at
all? Just get the output of "df -hT" and then search the corresponding
strings using a for loop...
e.g.
function GetDFOfSda2: String;
var
slist: TStringList;
s: String;
begin
slist := TStringList.Create;
try
GetOutputOfProcess('df', ['-hT'], slist); // hypothetic function
that returns the output of a process in a TStringList
for s in slist do begin
if (Pos('tmpfs', s) = 0) and (Pos('ecryptfs', s) = 0) then
Continue;
if Pos('sda2', s) > 0 then
Exit(s);
end;
finally
slist.Free;
end;
end.
Of course this can be improved by using regular expressions and setting
the drive to look for through a parameter, but it should show you the
basic concept. :)
Regards,
Sven
More information about the Lazarus
mailing list