From: Per Sandberg <per.s.sandberg@bahnhof.se>
Subject: Re: pass a argument to spawn
Date: Tue, 12 Jan 2016 08:12:58 +0100
Date: 2016-01-12T08:12:58+01:00 [thread overview]
Message-ID: <%H1ly.559632$hA3.555852@fx22.fr7> (raw)
In-Reply-To: <ea003744-e675-467f-9534-3305b6c05541@googlegroups.com>
Well
An argument_list is an array of String_Access and needs to be initialize
as such.
-------------------------------------------------------------------------
with GNAT.OS_Lib; use GNAT.OS_Lib;
with Ada.Text_IO; use Ada.Text_IO;
procedure Console_Ada is
State_Spawn : Boolean;
Arg : constant Argument_List :=
(1 => new String'("-a"));
-- Named association is needed since there is only one argument.
-- This construct also leaks memory but that does not matter here
-- since the program terminate immediate.
begin
Put_Line ("Print of your files :");
Spawn ("/bin/ls", Arg, State_Spawn);
Put (" Execution of the program with Spawn ? : " & State_Spawn'Img);
end Console_Ada;
-------------------------------------------------------------------------
/May i also suggest that you look into the GNAT.Expect package.
/Per
Den 2016-01-12 kl. 02:17, skrev comicfanzine@gmail.com:
> Hi , i'm trying to do a simple " ls -a " , on Ubuntu .
>
> I tried to associate a string value , because :
>
> subtype Argument_List is String_List;
>
> But it failed .
>
> Anyway , i'm lost with all the types and subtypes in GNAT.OS_Lib and System.Strings .
>
> So , i don't know how to proceed in the simplier way .
>
> WITH GNAT.OS_Lib ; USE GNAT.OS_Lib ;
> WITH Ada.Text_IO ; USE Ada.Text_IO ;
>
> procedure console_Ada is
>
> state_spawn : boolean ;
>
> arg : Argument_List ( 1..1 ) ;
> -- here the value must be "-a" .
>
> begin
>
> new_line ;
>
> put_line ( " Print of your files :") ;
>
> new_line ;
>
> Spawn ( "/bin/ls" , arg , state_spawn );
> -- /bin/ls -a
>
> new_line ;
>
> put ( " Execution of the program with Spawn ? : " & Boolean'Image( state_spawn ) ) ;
>
> end console_Ada ;
>
next prev parent reply other threads:[~2016-01-12 7:12 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-12 1:17 pass a argument to spawn comicfanzine
2016-01-12 7:05 ` Anh Vo
2016-01-12 7:12 ` Per Sandberg [this message]
2016-01-12 13:48 ` comicfanzine
2016-01-12 16:10 ` Björn Lundin
2016-01-12 19:36 ` comicfanzine
2016-01-12 20:58 ` Per Sandberg
2016-01-17 17:28 ` comicfanzine
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox