comp.lang.ada
 help / color / mirror / Atom feed
* retrieve command result
@ 2002-11-06 16:43 evangeli
  2002-11-06 17:06 ` sk
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: evangeli @ 2002-11-06 16:43 UTC (permalink / raw)


hi all

is it possible to retrieve the result of a command in a variable.
i explain myself:

------------------------------------------------------------------
with GNAT.OS_Lib;
with Ada.Strings.Unbounded;
procedure Test is
	...
	my_string : Ada.Strings.Unbounded.unbounded_string;
	...
begin
	...
	GNAT.OS_Lib.Spawn("ls", ...);
	-- I WOULD LIKE TO GET IN my_string THE RESULT OF THE ls COMMAND
	...
end;
------------------------------------------------------------------

i am under linux with gnat 3.13p.

thanks for any help




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: retrieve command result
  2002-11-06 16:43 retrieve command result evangeli
@ 2002-11-06 17:06 ` sk
  2002-11-06 17:46 ` Stephen Leake
  2002-11-07  1:48 ` Marc A. Criley
  2 siblings, 0 replies; 7+ messages in thread
From: sk @ 2002-11-06 17:06 UTC (permalink / raw)


Hi,
 
evangeli <evangeli@cnam.fr>
> GNAT.OS_Lib.Spawn("ls", ...);
> -- I WOULD LIKE TO GET IN my_string THE RESULT OF
> THE ls COMMAND

That looks like a load of fun ... :-)

How about Gnat.Directory_Operations ? 

-- 
-------------------------------------
-- Merge vertically for real address
-------------------------------------
s n p @ t . o
 k i e k c c m
-------------------------------------



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: retrieve command result
  2002-11-06 16:43 retrieve command result evangeli
  2002-11-06 17:06 ` sk
@ 2002-11-06 17:46 ` Stephen Leake
  2002-11-07  9:43   ` Emmanuel Briot
  2002-11-07  1:48 ` Marc A. Criley
  2 siblings, 1 reply; 7+ messages in thread
From: Stephen Leake @ 2002-11-06 17:46 UTC (permalink / raw)


evangeli <evangeli@cnam.fr> writes:

> hi all
> 
> is it possible to retrieve the result of a command in a variable.
> i explain myself:
> 
> ------------------------------------------------------------------
> with GNAT.OS_Lib;
> with Ada.Strings.Unbounded;
> procedure Test is
> 	...
> 	my_string : Ada.Strings.Unbounded.unbounded_string;
> 	...
> begin
> 	...
> 	GNAT.OS_Lib.Spawn("ls", ...);
> 	-- I WOULD LIKE TO GET IN my_string THE RESULT OF THE ls COMMAND
> 	...
> end;
> ------------------------------------------------------------------
> 
> i am under linux with gnat 3.13p.

First, upgrade to 3.14p.

In general, you need to map the "standard output stream" of the
spawned program to a stream that you then read.

There is no Standard way to do this, and I see nothing in the GNAT
extensions for it either.

Linux has a spawn function that allows you to do this (sorry, I don't
know what it is called); find it in a Linux reference, import it into
Ada, and call it. Ideally, you should figure out how to use
Ada.Streams to provide the stream you read from.

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: retrieve command result
  2002-11-06 16:43 retrieve command result evangeli
  2002-11-06 17:06 ` sk
  2002-11-06 17:46 ` Stephen Leake
@ 2002-11-07  1:48 ` Marc A. Criley
  2002-11-07 15:46   ` evangeli
  2 siblings, 1 reply; 7+ messages in thread
From: Marc A. Criley @ 2002-11-07  1:48 UTC (permalink / raw)


evangeli wrote:
> 
> hi all
> 
> is it possible to retrieve the result of a command in a variable.
> i explain myself:

You are looking for "Pipes", which is an excellent piece of software
written by Jim Rogers.  It makes doing things like this very easy.

http://www.adapower.com/reuse/pipes.html

Marc A. Criley
Quadrus Corporation
www.quadruscorp.com



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: retrieve command result
  2002-11-06 17:46 ` Stephen Leake
@ 2002-11-07  9:43   ` Emmanuel Briot
  2002-11-07 13:56     ` Stephen Leake
  0 siblings, 1 reply; 7+ messages in thread
From: Emmanuel Briot @ 2002-11-07  9:43 UTC (permalink / raw)


Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov> writes:

> evangeli <evangeli@cnam.fr> writes:
> > is it possible to retrieve the result of a command in a variable.
> > i explain myself:

> There is no Standard way to do this, and I see nothing in the GNAT
> extensions for it either.


There is a package, which I think was already there with 3.14p, called
GNAT.Except which can be used to do this sort of things. It is more aimed at
interactive programs, where you want to keep sending input and receiving output
from the second process, but it might be used in the simple scenario you want
as well.
This is portable to most systems where GNAT is ported (apart from VMS I
believe), and is the package used by GVD to communicate with gdb.

Emmanuel



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: retrieve command result
  2002-11-07  9:43   ` Emmanuel Briot
@ 2002-11-07 13:56     ` Stephen Leake
  0 siblings, 0 replies; 7+ messages in thread
From: Stephen Leake @ 2002-11-07 13:56 UTC (permalink / raw)


Emmanuel Briot <briot@act-europe.fr> writes:

> There is a package, which I think was already there with 3.14p, called
> GNAT.Except 

Actually, it's GNAT.Expect. It is in GNAT 3.14p.

Thanks for pointing this out!

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: retrieve command result
  2002-11-07  1:48 ` Marc A. Criley
@ 2002-11-07 15:46   ` evangeli
  0 siblings, 0 replies; 7+ messages in thread
From: evangeli @ 2002-11-07 15:46 UTC (permalink / raw)


> evangeli wrote:
> 
>>hi all
>>
>>is it possible to retrieve the result of a command in a variable.
>>i explain myself:
>>
> 
> You are looking for "Pipes", which is an excellent piece of software
> written by Jim Rogers.  It makes doing things like this very easy.
> 
> http://www.adapower.com/reuse/pipes.html
> 
> Marc A. Criley
> Quadrus Corporation
> www.quadruscorp.com
> 


thank u for your response.

it works fine, but this advantage with the spawns functions of the 
GNAT.OS_Lib was that i was able to stop a process or wait for its 
completion, which is not possible now. any idea?

Sami Evangelista





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-11-07 15:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-06 16:43 retrieve command result evangeli
2002-11-06 17:06 ` sk
2002-11-06 17:46 ` Stephen Leake
2002-11-07  9:43   ` Emmanuel Briot
2002-11-07 13:56     ` Stephen Leake
2002-11-07  1:48 ` Marc A. Criley
2002-11-07 15:46   ` evangeli

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