From: jerry@jvdsys.nextjk.stuyts.nl (Jerry van Dijk)
Subject: Re: Need help re: System Calls
Date: 1997/04/08
Date: 1997-04-08T00:00:00+00:00 [thread overview]
Message-ID: <860461839.15snx@jvdsys.nextjk.stuyts.nl> (raw)
>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
next reply other threads:[~1997-04-08 0:00 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-04-08 0:00 Jerry van Dijk [this message]
[not found] <Pine.SGI.3.94.970406210904.4241A-100000@sandcast <860461839.15snx@jvdsys.nextjk.stuyts.nl>
1997-04-09 0:00 ` Need help re: System Calls Keith Thompson
-- strict thread matches above, loose matches on Subject: below --
1997-04-07 0:00 Chris Morgan
1997-04-07 0:00 ` Robert Dewar
1997-04-10 0:00 ` Keith Thompson
1997-04-12 0:00 ` Robert Dewar
1997-04-12 0:00 ` Robert Dewar
1997-04-13 0:00 ` Larry Kilgallen
1997-04-13 0:00 ` Robert Dewar
1997-04-14 0:00 ` Keith Thompson
1997-04-06 0:00 Bill Roland
1997-04-07 0:00 ` Robert Dewar
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox