comp.lang.ada
 help / color / mirror / Atom feed
From: "Warren W. Gay VE3WWG" <ve3wwg@cogeco.ca>
Subject: Re: Running external program, getting output
Date: Fri, 27 Jun 2003 13:47:15 -0400
Date: 2003-06-27T13:47:15-04:00	[thread overview]
Message-ID: <3EFC8323.1060501@cogeco.ca> (raw)
In-Reply-To: m2n0g5hoy7.fsf@maskin.flamestrike.no-ip.org

Jarle Thorsen wrote:
> Martin Krischik <krischik@users.sourceforge.net> 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




      parent reply	other threads:[~2003-06-27 17:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-22 11:51 Running external program, getting output Jarle Thorsen
2003-06-22 13:07 ` Ludovic Brenta
2003-06-22 13:43   ` sk
2003-06-22 15:39     ` Jarle Thorsen
2003-06-22 19:21       ` David C. Hoos
2003-06-22 19:25       ` sk
2003-06-22 17:20 ` Martin Krischik
2003-06-25 20:39   ` Jarle Thorsen
2003-06-26  2:04     ` sk
2003-06-27 17:47     ` Warren W. Gay VE3WWG [this message]
replies disabled

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