comp.lang.ada
 help / color / mirror / Atom feed
* Re: Need help re: System Calls
@ 1997-04-08  0:00 Jerry van Dijk
  0 siblings, 0 replies; 12+ messages in thread
From: Jerry van Dijk @ 1997-04-08  0:00 UTC (permalink / 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




^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: Need help re: System Calls
@ 1997-04-07  0:00 Chris Morgan
  1997-04-07  0:00 ` Robert Dewar
  0 siblings, 1 reply; 12+ messages in thread
From: Chris Morgan @ 1997-04-07  0:00 UTC (permalink / raw)



In article <dewar.860415799@merv> dewar@merv.cs.nyu.edu (Robert Dewar)
writes:

> 
> Bill asks
> 
> <<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).>>
> 
> Remember that the specs of the g-* units in the GNAT library are an important
> part of the documentation. These is a collection of useful stuff distributed
> with GNAT, and the specs (ads files) act as the documentation. To answer
> this question look at GNAT.OS_Lib.Spawn in g-os_lib.ads.
> 

And failing that just pragma interface to the C routine "system". I've
got an example at work if you want (drop me a line in that case) which
tests whether a file is a named pipe using the shell. Ok it's gross
but it helped :-)
-- 
Chris Morgan (cm@mihalis.demon.co.uk)




^ permalink raw reply	[flat|nested] 12+ messages in thread
* Need help re: System Calls
@ 1997-04-06  0:00 Bill Roland
  1997-04-07  0:00 ` Robert Dewar
  0 siblings, 1 reply; 12+ messages in thread
From: Bill Roland @ 1997-04-06  0:00 UTC (permalink / 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).

Bill Roland
wr94ae@sandcastle.cosc.brocku.ca






^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~1997-04-14  0:00 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [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
1997-04-08  0:00 Jerry van Dijk
  -- 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox