From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Received: by 2002:ac8:93d:: with SMTP id t58mr6495005qth.217.1572283479874; Mon, 28 Oct 2019 10:24:39 -0700 (PDT) X-Received: by 2002:aca:3386:: with SMTP id z128mr304284oiz.122.1572283479527; Mon, 28 Oct 2019 10:24:39 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!j16no8980101qtl.0!news-out.google.com!x9ni379qti.1!nntp.google.com!j16no8980096qtl.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 28 Oct 2019 10:24:39 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2a02:a03f:e3e9:4d00:1260:4bff:fe89:deb2; posting-account=kTRirAoAAACnF_wtAOSamxYBSVvmJuCa NNTP-Posting-Host: 2a02:a03f:e3e9:4d00:1260:4bff:fe89:deb2 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: How to run external program pipeline and capture output From: Alain De Vos Injection-Date: Mon, 28 Oct 2019 17:24:39 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:57357 Date: 2019-10-28T10:24:39-07:00 List-Id: 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;