comp.lang.ada
 help / color / mirror / Atom feed
From: Anh Vo <anhvofrcaus@gmail.com>
Subject: Re: pass a argument to spawn
Date: Mon, 11 Jan 2016 23:05:23 -0800 (PST)
Date: 2016-01-11T23:05:23-08:00	[thread overview]
Message-ID: <a824f1ac-bc80-4cab-9b20-9d12045c484a@googlegroups.com> (raw)
In-Reply-To: <ea003744-e675-467f-9534-3305b6c05541@googlegroups.com>

On Monday, January 11, 2016 at 5:17:50 PM UTC-8, comicf...@gmail.com wrote:
> 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 ;

Why mess with low level while there is a simpler way. Here is a quick binding to the system call as shown below.

with Interfaces.C;

function Invoke_System (Name :string) return Integer is
	
   C_Name : constant Interfaces.C.Char_Array (1 .. Name'Length + 1) := 
		                                  Interfaces.C.To_C(Name);

   function C_system (Name : System.Address) return Interfaces.C.int;
   pragma Import(C, C_system, "system");

begin
   return integer (C_system(C_Name(1)'address));
end;

procedure Invoke_System (Name : String) is
   Dummy : Integer;
begin
   Dummy := Invoke_System(Name);
end Invoke_System;

--...

declare
   Unix_Command : constant String := "ls -a";
begin
   Invoke_System (Unix_Command);
end;

Anh Vo


  reply	other threads:[~2016-01-12  7:05 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 [this message]
2016-01-12  7:12 ` Per Sandberg
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