* Run external program pipeline and capture output
@ 2019-10-28 17:33 Alain De Vos
0 siblings, 0 replies; only message in thread
From: Alain De Vos @ 2019-10-28 17:33 UTC (permalink / raw)
Code below produces no output.
However with
Command : String := "/usr/local/bin/zsh -c ""/bin/ls""";
it works which is very weird.
Any idea ?
----BEGIN PROCEDURE RUNCOMMAND
procedure System_Command is
Command : String := "/usr/local/bin/zsh -c ""/bin/ls | /usr/bin/grep a""";
Args : Argument_List_Access;
Status : aliased Integer;
Separators : constant String := LF & CR;
Reply_List : Slice_Set;
begin
Ada.Text_IO.Put_Line (Command);
Args := Argument_String_To_List (Command);
-- execute the system command and get the output in a single string
declare
Response : String :=
Get_Command_Output
(Command => Args (Args'First).all,
Arguments => Args (Args'First + 1 .. Args'Last),
Input => "",
Status => Status'Access);
begin
Free (Args);
-- split the output in a slice for easier manipulation
if Status = 0 then
Create (S => Reply_List,
From => Response,
Separators => Separators,
Mode => Multiple);
end if;
end;
-- do something with the system output. Just print it out
for I in 1 .. Slice_Count (Reply_List) loop
Put_Line (Slice (Reply_List, I));
end loop;
end System_Command;
----END PROCEDURE RUNCOMMAND
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-10-28 17:33 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-28 17:33 Run external program pipeline and capture output Alain De Vos
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox