comp.lang.ada
 help / color / mirror / Atom feed
From: Alain De Vos <devosalain71@gmail.com>
Subject: How to run external program pipeline and capture output
Date: Mon, 28 Oct 2019 10:24:39 -0700 (PDT)
Date: 2019-10-28T10:24:39-07:00	[thread overview]
Message-ID: <d9fec393-d0b0-4be0-91bf-0b39cb9f42a4@googlegroups.com> (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;


             reply	other threads:[~2019-10-28 17:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-28 17:24 Alain De Vos [this message]
2019-10-29 10:31 ` How to run external program pipeline and capture output joakimds
2019-10-29 16:47   ` Jeffrey R. Carter
2019-10-30 13:41     ` Shark8
replies disabled

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