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=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,cc1e5a80c87c0755 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-27 10:54:24 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!news-in.mts.net!nf1.bellglobal.com!nf2.bellglobal.com!news20.bellglobal.com.POSTED!not-for-mail Message-ID: <3EFC8323.1060501@cogeco.ca> From: "Warren W. Gay VE3WWG" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Running external program, getting output References: <5972474.ITsLBhBNCF@linux1.krischik.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Fri, 27 Jun 2003 13:47:15 -0400 NNTP-Posting-Host: 198.96.223.163 X-Complaints-To: abuse@sympatico.ca X-Trace: news20.bellglobal.com 1056736034 198.96.223.163 (Fri, 27 Jun 2003 13:47:14 EDT) NNTP-Posting-Date: Fri, 27 Jun 2003 13:47:14 EDT Organization: Bell Sympatico Xref: archiver1.google.com comp.lang.ada:39841 Date: 2003-06-27T13:47:15-04:00 List-Id: Jarle Thorsen wrote: > Martin Krischik writes: >>Jarle Thorsen wrote: >>>As far as I have gathered the best way of (non OS-specific) running an >>>external program from Ada is using the Spawn procedure in g-os_lib, >>>correct ? >>> >>>But how do I get the output from the command that I run? Lets say that I >>>want to run "ls" for example..... >> >>AdaCL has a support class do just this. See TestCommand (test 3) on how to >>do it: >> >>http://adacl.sourceforge.net/html/TestCommand-Main__adb.htm >> >>You find AdaCL at: >> >>http://www.ada.krischik.com >> >>Also, you can use the GNAT.Expect package. > > Reading your suggestions and also packages provided by other posters I am > getting really unsure which way to go... > > My main focus is making it as portable as possible, yet as simple as > possible. > > My program will 90% percent of the time wait for the spawned program to end > before printing its output, but will on some occations read information > from the program's pipe while it is still running.... What you are experiencing is the fact that commands that provide output (to the pipe), have buffered I/O in many situations (perhaps not all). This buffer is in the application that is being run. Iff the output is buffered, then indeed, you will not see a small amount of output, until the running application closes the standard output (this forces a flush of the write buffer). BUT(!) most (if not all) UNIX program libraries are designed to NOT buffer output when the output device is a tty or a pipe. However, if you end up using the popen(3) call in libc that returns a FILE *, then this too will use a buffer. This is probably what is causing your "experience". To change this, you need to do a setbuf(File,_IONBF) in C terms to eliminate the buffer. I havn't actually tried this with peopen(3), but I can't see why it would fail. This is certainly what you want in this case. To do this, you'll either have to find the appropriate Binding API to cause this, or you may have to create your own binding to accomplish this. > > Any clues on which solution to choose ? So to answer your question, if the buffering is a concern, then choose the one that permits you to control buffering. If neither does it, then other factors enter into the choice. ;-) -- Warren W. Gay VE3WWG http://home.cogeco.ca/~ve3wwg