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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8be452774bba3c5f X-Google-Attributes: gid103376,public From: jerry@jvdsys.nextjk.stuyts.nl (Jerry van Dijk) Subject: Re: Need help re: System Calls Date: 1997/04/08 Message-ID: <860461839.15snx@jvdsys.nextjk.stuyts.nl>#1/1 X-Deja-AN: 231473334 Distribution: world References: >I am looking for information about how to perform system calls (in this >case, UNIX commands) in the GNAT compiler of Ada 95. Any help would be >appreciated. (Note: in this case, I am trying to implement a command which >is stored in a string). Usually unix has a C library function to execute another program, for example: int system (constant char *command) using GNAT, simply import this library function and call it directly, using the standard C interface as defined in Appendix B.3. In this case you can take advantage of the fact that for GNAT Interfaces.C.int equals Integer. But, as you also need to convert the Ada string into a C-type zero terminated ascii character array, it is probably useful to put a wrapper around the C library call: with Interfaces.C; procedure Demo is function Call_System (Command : String) return Integer is function system (Command : Interfaces.C.char_array) return Integer; pragma Import (C, system); begin return system (Interfaces.C.To_C (Command)); end Call_System; Result : Integer; begin Result := Call_System ("ls"); end Demo; Note that importing 'system' as a C function automatically takes care of calling the function with a pointer to the character array. -- -- Jerry van Dijk | Haarlem, Holland -- Business Consultant | Team Ada -- Ordina Finance | jdijk@acm.org