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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6bcdc23b05684cbe X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-30 00:25:12 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!newsmm00.sul.t-online.com!t-online.de!news.t-online.com!not-for-mail From: Martin Krischik Newsgroups: comp.lang.ada Subject: Re: Newbie GNAT question Date: Wed, 29 Oct 2003 17:18:30 +0100 Organization: AdaCL Message-ID: <2769004.oqcxehEVWl@linux1.krischik.com> References: <3702372.KgjAOxL2ds@linux1.krischik.com> Reply-To: krischik@users.sourceforge.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.t-online.com 1067502137 00 1290 I43NVvUSeYfyb 031030 08:22:17 X-Complaints-To: usenet-abuse@t-online.de X-ID: GbPc9BZOgeKF5IFrCBeAjo0YKjdk8d7ByWQlb87rzwcFPs49Ys2pcW User-Agent: KNode/0.7.2 Xref: archiver1.google.com comp.lang.ada:1841 Date: 2003-10-29T17:18:30+01:00 List-Id: sk wrote: > krischik@users.sourceforge.net: > > However there is not Free_Arguement_List (...) in > > Gnat.Os_Lib. But don't despair there is one in > > AdaCL.OS.Command. > > Do you need one ? > > declare > Cmd : constant String := "/bin/ls"; > Args : constant String := Gnat.Os_Lib.Arguement_String_To_List > ("-al"); Success : Boolean := False; > begin > Gnat.Os_Lib.Spawn (Cmd, Args, Success); > > -- Check success and continue ... > > end; > > OR > > .... > Gnat.Os_Lib.Spawn ( > Command => "/bin/ls", > Args => Gnat.Os_Lib.Argument_String_To_List ("-al"), > Success => Success > ); > > I believe that there is no need for a "Free" in either case :-) If you like memory leaks or have a special GNAT with full gargage collection then not. For anybody else, look closer: Args is an Argument_List: procedure Spawn (Program_Name : String; Args : Argument_List; Success : out Boolean) An Argument_List is an of access to string: type String_Access is access all String; subtype Argument_List is String_List; And unlike common belive Gnat.Os_Lib.Spawn will not free the Args ot any of the strings contained: begin -- Copy arguments into a local structure for K in N_Args'Range loop N_Args (K) := new String'(Args (K).all); end loop; -- Normalize those arguments Normalize_Arguments (N_Args); -- Call spawn using the normalized arguments Spawn (N_Args); -- Free arguments list for K in N_Args'Range loop Free (N_Args (K)); end loop; end Spawn_Internal; It makes copy for Normalize_Arguments and frees that copy but not the original. BTW: it can't since it is "access _all_ String;" - you can create the Args with strings from the stack. You can of course use AdaCL.OS.Command: http://adacl.sourceforge.net/html/______Include__AdaCL-OS-Command__ads.htm Which does not leak memory and who's Argument_String_To_List is lot more powerfull: -- -- Convert a String into an argument list. Unlike the -- version of GNAT.OS this version strips the double -- quotes. You will need this if you want to execute -- command with spaces inside a filename. -- -- Also you can freely choose the Seperator, Quotation -- and escape character. This makes it easier to compose -- commandlines where you need the characters usualy used -- for this purpouse. -- function Argument_String_To_List ( -- Argument string. Arguments with spaces should be -- quoted. Arg_String : in String; -- Character seperating Arguments. Other options -- which might be used here are: -- -- Ada.Characters.Latin_1.NUL -- Ada.Characters.Latin_1.LF Seperator : in Character := Ada.Characters.Latin_1.Space; -- Character to enclose Arguments. This overwrites -- the seperator character. Other options -- which might be used here are: -- -- Ada.Characters.Latin_1.Apostrophe Quotation : in Character := Ada.Characters.Latin_1.Quotation; -- Character to remove special meaning of next -- character. Other options which might be used here are: -- -- Ada.Characters.Latin_1.ESC Escape : in Character := Ada.Characters.Latin_1.Reverse_Solidus) return GNAT.OS_Lib.Argument_List_Access; With Regards Martin -- mailto://krischik@users.sourceforge.net http://www.ada.krischik.com