comp.lang.ada
 help / color / mirror / Atom feed
* How to run external program pipeline and capture output
@ 2019-10-28 17:24 Alain De Vos
  2019-10-29 10:31 ` joakimds
  0 siblings, 1 reply; 4+ messages in thread
From: Alain De Vos @ 2019-10-28 17:24 UTC (permalink / raw)


I like to run a command like :
/usr/local/bin/zsh -c "/bin/ls | /usr/bin/grep a"
But the procedure below produces no ouput, 

To make it strange, with /usr/local/bin/zsh -c "/bin/ls " it works fine.

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;


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-10-30 13:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-28 17:24 How to run external program pipeline and capture output Alain De Vos
2019-10-29 10:31 ` joakimds
2019-10-29 16:47   ` Jeffrey R. Carter
2019-10-30 13:41     ` Shark8

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox