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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.66.157.37 with SMTP id wj5mr116428866pab.30.1452582323940; Mon, 11 Jan 2016 23:05:23 -0800 (PST) X-Received: by 10.182.97.194 with SMTP id ec2mr219503obb.1.1452582323872; Mon, 11 Jan 2016 23:05:23 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!h5no3299954igh.0!news-out.google.com!kr2ni2599igb.0!nntp.google.com!o2no2152189iga.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 11 Jan 2016 23:05:23 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=24.6.21.101; posting-account=Qh2kiQoAAADpCLlhT_KTYoGO8dU3n4I6 NNTP-Posting-Host: 24.6.21.101 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: pass a argument to spawn From: Anh Vo Injection-Date: Tue, 12 Jan 2016 07:05:23 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:29097 Date: 2016-01-11T23:05:23-08:00 List-Id: 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