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=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!feeder1.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!buffer1.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 17 Oct 2019 10:34:23 -0500 From: Dennis Lee Bieber Newsgroups: comp.lang.ada Subject: Re: execute external shell program and process the output line by line Date: Thu, 17 Oct 2019 11:34:24 -0400 Organization: IISS Elusive Unicorn Message-ID: <7dvgqepj9eljll1mnt9kcdbcvi69bmc3ue@4ax.com> References: <69956c86-273a-40c4-b1d8-dc5c7a8e960f@googlegroups.com> User-Agent: ForteAgent/8.00.32.1272 X-No-Archive: YES MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-7Ohi/Kgy2hr+E+ZfPHmy1ir0RiMNt5I5RXSVtQFhG7YTCzCV/tfXgLpbMRpvVCRudBbIdnafsw/ubJd!89OLrhb3IxpqMcwIjFUdFUdbPtVniC3A7feRVeRI0Io0QNBYzKgt116Ce6ay+MqiFFcNIlYf X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 5497 Xref: reader01.eternal-september.org comp.lang.ada:57315 Date: 2019-10-17T11:34:24-04:00 List-Id: On Thu, 17 Oct 2019 05:25:26 -0700 (PDT), devosalain71@gmail.com declaimed the following: >I need the call a process like "ls", >And process the output line by line. >So it is not sufficient if i have the return code success or error. So... first question: which compiler suite? I'm going to presume Linux compatible given the specification of "ls". GNAT extension libraries cover some of this need. I would also mention that "ls" may not be the best example. If your really mean that the command you need the output from IS "ls" you might find that you don't need it at all if using GNAT: """ 12.68. GNAT.Directory_Operations (g-dirope.ads) Provides a set of routines for manipulating directories, including changing the current directory, making new directories, and scanning the files in a directory. 12.69. GNAT.Directory_Operations.Iteration (g-diopit.ads) A child unit of GNAT.Directory_Operations providing additional operations for iterating through directories. """ However, even that library has likely been superceded in Ada 2005 and later by ada.directories """ Ada.Directories (A.16) This package provides operations on directories. Ada.Directories.Hierarchical_File_Names (A.16.1) This package provides additional directory operations handling hiearchical file names. Ada.Directories.Information (A.16) This is an implementation defined package for additional directory operations, which is not implemented in GNAT. """ example: """ procedure Start_Search (Search : in out Search_Type; Directory : String; Pattern : String; Filter : Filter_Type := (others => True)); -- Starts a search in the directory entry in the directory named by -- Directory for entries matching Pattern. Pattern represents a file name -- matching pattern. If Pattern is null, all items in the directory are -- matched; otherwise, the interpretation of Pattern is implementation- -- defined. Only items which match Filter will be returned. After a -- successful call on Start_Search, the object Search may have entries -- available, but it may have no entries available if no files or -- directories match Pattern and Filter. The exception Name_Error is -- propagated if the string given by Directory does not identify an -- existing directory, or if Pattern does not allow the identification of -- any possible external file or directory. The exception Use_Error is -- propagated if the external environment does not support the searching -- of the directory with the given name (in the absence of Name_Error). """ And for those where you must run an external command, there are things in GNAT extensions like: """ 12.77. GNAT.Expect (g-expect.ads) Provides a set of subprograms similar to what is available with the standard Tcl Expect tool. It allows you to easily spawn and communicate with an external process. You can send commands or inputs to the process, and compare the output with some expected regular expression. Currently GNAT.Expect is implemented on all native GNAT ports. It is not implemented for cross ports, and in particular is not implemented for VxWorks or LynxOS. """ The more general mode would be to have the output of the command written to a file, and then open/read the file... From system.os_lib (probably another GNAT extension) """ procedure Spawn (Program_Name : String; Args : Argument_List; Output_File : String; Success : out Boolean; Return_Code : out Integer; Err_To_Out : Boolean := True); -- Similar to the procedure above, but saves the output of the command to -- a file with the name Output_File. -- -- Success is set to True if the command is executed and its output -- successfully written to the file. If Success is True, then Return_Code -- will be set to the status code returned by the operating system. -- Otherwise, Return_Code is undefined. -- -- Spawning processes from tasking programs is not recommended. See -- "NOTE: Spawn in tasking programs" below. """ -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/