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,FREEMAIL_FROM, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,439c480fcf4ce979 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-01-14 00:58:29 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!nycmny1-snh1.gtei.net!nycmny1-snf1.gtei.net!news.gtei.net!newsfeed-zh.ip-plus.net!news.ip-plus.net!not-for-mail From: Thomas Wolf Newsgroups: comp.lang.ada Subject: Re: Exec shell command with GNAT Date: Tue, 14 Jan 2003 09:58:24 +0100 Organization: --- Message-ID: References: Reply-To: t_wolf@angelfire.com NNTP-Posting-Host: pargate2.paranor.ch X-Trace: rex.ip-plus.net 1042534694 14380 195.65.4.190 (14 Jan 2003 08:58:14 GMT) X-Complaints-To: abuse@ip-plus.net NNTP-Posting-Date: Tue, 14 Jan 2003 08:58:14 +0000 (UTC) X-Newsreader: MicroPlanet Gravity v2.60 Xref: archiver1.google.com comp.lang.ada:32997 Date: 2003-01-14T09:58:24+01:00 List-Id: david.c.hoos.sr@ada95.com wrote: > with Ada.Characters.Latin_1; > with System; > function Execute_Shell_Command > (The_Command : String) return Integer is > > function Execute > (The_Command_Address : System.Address) return Integer; > pragma Import (C, Execute, "system"); > The_Nul_Terminated_Command_String : constant String := > The_Command & Ada.Characters.Latin_1.Nul; > begin > return Execute (The_Nul_Terminated_Command_String'Address); > end Execute_Shell_Command; Yes, that's it. My own version looks similar: with Interfaces.C; function Execute (Command : in String) return Integer is function Run (Command : in Interfaces.C.char_array) return Interfaces.C.int; pragma Import (C, Run, "system"); begin -- Execute return Integer (Run (Interfaces.C.To_C (Item => Command))); end Execute; No fiddling around with addresses needed, and the declaration of "Run" doesn't depend on Interfaces.C.int and Integer being the same. Note that the Ada standard guarantees that an in-parameter of an array of some element_type is passed in a way compatible with an "element_type *" in C. (I.e., the address of the first element is passed.) -- ----------------------------------------------------------------- Thomas Wolf e-mail: t_wolf@angelfire.com