comp.lang.ada
 help / color / mirror / Atom feed
* 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

* Re: Need help re: System Calls
  1997-04-06  0:00 Need help re: System Calls Bill Roland
@ 1997-04-07  0:00 ` Robert Dewar
  0 siblings, 0 replies; 12+ messages in thread
From: Robert Dewar @ 1997-04-07  0:00 UTC (permalink / raw)



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.





^ 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

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



Chris says

<<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 :-)>>

The advantage of using Spawn is that it will work in a similar manner
on all operating systems with GNAT compilers.





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

* 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
       [not found] <Pine.SGI.3.94.970406210904.4241A-100000@sandcast <860461839.15snx@jvdsys.nextjk.stuyts.nl>
@ 1997-04-09  0:00 ` Keith Thompson
  0 siblings, 0 replies; 12+ messages in thread
From: Keith Thompson @ 1997-04-09  0:00 UTC (permalink / raw)



In <860461839.15snx@jvdsys.nextjk.stuyts.nl> jerry@jvdsys.nextjk.stuyts.nl (Jerry van Dijk) writes:
[...]
> In this case you can take advantage of the fact that for GNAT
> Interfaces.C.int equals Integer.

How is this an advantage?  What's wrong with using Interfaces.C.int?

>                                  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:
[code deleted]

As long as you're putting a wrapper around it, let the wrapper do the
conversion from Interfaces.C.int to Integer.

-- 
Keith Thompson (The_Other_Keith) kst@sd.aonix.com <http://www.aonix.com> <*>
TeleSo^H^H^H^H^H^H Alsy^H^H^H^H Thomson Softw^H^H^H^H^H^H^H^H^H^H^H^H^H Aonix
5040 Shoreham Place, San Diego, CA, USA, 92122-5989
"Humor is such a subjective thing." -- Cartagia




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

* Re: Need help re: System Calls
  1997-04-07  0:00 ` Robert Dewar
@ 1997-04-10  0:00   ` Keith Thompson
  1997-04-12  0:00     ` Robert Dewar
  1997-04-13  0:00     ` Larry Kilgallen
  0 siblings, 2 replies; 12+ messages in thread
From: Keith Thompson @ 1997-04-10  0:00 UTC (permalink / raw)



In <dewar.860462789@merv> dewar@merv.cs.nyu.edu (Robert Dewar) writes:
[...]
> The advantage of using Spawn is that it will work in a similar manner
> on all operating systems with GNAT compilers.

The disadvantage of using Spawn is that it will only work with GNAT
compilers -- unless you write your own Spawn routine, which shouldn't
be too difficult.

-- 
Keith Thompson (The_Other_Keith) kst@sd.aonix.com <http://www.aonix.com> <*>
TeleSo^H^H^H^H^H^H Alsy^H^H^H^H Thomson Softw^H^H^H^H^H^H^H^H^H^H^H^H^H Aonix
5040 Shoreham Place, San Diego, CA, USA, 92122-5989
"Humor is such a subjective thing." -- Cartagia




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

* Re: Need help re: System Calls
  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
  1 sibling, 1 reply; 12+ messages in thread
From: Robert Dewar @ 1997-04-12  0:00 UTC (permalink / raw)



<<The disadvantage of using Spawn is that it will only work with GNAT
compilers -- unless you write your own Spawn routine, which shouldn't
be too difficult.>>

Or borrow the Spawn from GNAT, I don't think that unit uses much special
GNAT stuff. Borrowing runtime stuff from GNAT to use with other Ada 95
compilers is perfectly possible (in fact last I knew Aonix delivered
Object Ada with some of the intact -- though somewhat out of date --
library units from GNAT).





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

* Re: Need help re: System Calls
  1997-04-12  0:00     ` Robert Dewar
@ 1997-04-12  0:00       ` Robert Dewar
  0 siblings, 0 replies; 12+ messages in thread
From: Robert Dewar @ 1997-04-12  0:00 UTC (permalink / raw)



I said in a previous msg

<<Or borrow the Spawn from GNAT, I don't think that unit uses much special
GNAT stuff. Borrowing runtime stuff from GNAT to use with other Ada 95
compilers is perfectly possible (in fact last I knew Aonix delivered
Object Ada with some of the intact -- though somewhat out of date --
library units from GNAT).
>>

One thing I should add here is that it is definitely NOT the case that
all GNAT units can be borrowed. I have run across a number of situations
in which people expected for example that they could get the facilities
of the information systems annex just by borrowing the relevant GNAT
packages but that won't work unless:

(a) Your compiler supports high precision decimal types with proper 
Ada 95 semantics (i.e. decimal semantics, not ordinary fixed-point semantics)

(b) Your compiler supports the necssary intrinsic subprograms and other
special GNAT features.






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

* Re: Need help re: System Calls
  1997-04-10  0:00   ` Keith Thompson
  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
  1 sibling, 2 replies; 12+ messages in thread
From: Larry Kilgallen @ 1997-04-13  0:00 UTC (permalink / raw)



In article <E8EBpJ.CyD@thomsoft.com>, kst@sd.aonix.com (Keith Thompson) writes:
> In <dewar.860462789@merv> dewar@merv.cs.nyu.edu (Robert Dewar) writes:
> [...]
>> The advantage of using Spawn is that it will work in a similar manner
>> on all operating systems with GNAT compilers.
> 
> The disadvantage of using Spawn is that it will only work with GNAT
> compilers -- unless you write your own Spawn routine, which shouldn't
> be too difficult.

I understood "spawn" from this discussion to provide access to a CLI,
but what is valid from that point on certainly varies between
operating systems, and as I understand it, even between Unix
variants.  In general it would seem that portability of access
to "system" capabilities is not helpful between domains where
those capabilities are not identical.

Larry Kilgallen




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

* Re: Need help re: System Calls
  1997-04-13  0:00     ` Larry Kilgallen
@ 1997-04-13  0:00       ` Robert Dewar
  1997-04-14  0:00       ` Keith Thompson
  1 sibling, 0 replies; 12+ messages in thread
From: Robert Dewar @ 1997-04-13  0:00 UTC (permalink / raw)



Larry says

<<I understood "spawn" from this discussion to provide access to a CLI,
but what is valid from that point on certainly varies between
operating systems, and as I understand it, even between Unix
variants.  In general it would seem that portability of access
to "system" capabilities is not helpful between domains where
those capabilities are not identical.>>

Much too pessimistic, have a look at the internal use of Spawn within
GNAT, we have found ways to use it that give portability over a very
wide range of systems ...





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

* Re: Need help re: System Calls
  1997-04-13  0:00     ` Larry Kilgallen
  1997-04-13  0:00       ` Robert Dewar
@ 1997-04-14  0:00       ` Keith Thompson
  1 sibling, 0 replies; 12+ messages in thread
From: Keith Thompson @ 1997-04-14  0:00 UTC (permalink / raw)



In <1997Apr12.220404.1@eisner> kilgallen@eisner.decus.org (Larry Kilgallen) writes:
[...]
> I understood "spawn" from this discussion to provide access to a CLI,
> but what is valid from that point on certainly varies between
> operating systems, and as I understand it, even between Unix
> variants.  In general it would seem that portability of access
> to "system" capabilities is not helpful between domains where
> those capabilities are not identical.

By the way, the system() function is part of the ISO C standard, so it's
very likely that you can use the features of Annex B to invoke it in a
nearly portable manner if there's a C library available on your system.

Here's the definition (typos mine):

    7.10.4.5 The system function

    Synopsis
	#include <stdlib.h>
	int system(const char *string);

    Description
    The system function passes the string pointed to by string to
    the host environment to be executed by a command processor in an
    implementation-defined manner.  A null pointer may be used for string
    to inquire whether a command processor exists.

    Returns
    If the argument is a null pointer, the system function returns nonzero
    only if a command processor is available.  If the argument is not a
    null pointer, the system function returns an implementation-defined
    value.

Of course, the interpretation of the parameter is entirely
implementation-defined.  On a Unix or Unix-like system, it's typically
passed to some version of the Bourne shell (/bin/sh).

-- 
Keith Thompson (The_Other_Keith) kst@sd.aonix.com <http://www.aonix.com> <*>
TeleSo^H^H^H^H^H^H Alsy^H^H^H^H Thomson Softw^H^H^H^H^H^H^H^H^H^H^H^H^H Aonix
5040 Shoreham Place, San Diego, CA, USA, 92122-5989
"Humor is such a subjective thing." -- Cartagia




^ 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 --
1997-04-06  0:00 Need help re: System Calls Bill Roland
1997-04-07  0:00 ` Robert Dewar
  -- 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-08  0:00 Jerry van Dijk
     [not found] <Pine.SGI.3.94.970406210904.4241A-100000@sandcast <860461839.15snx@jvdsys.nextjk.stuyts.nl>
1997-04-09  0:00 ` Keith Thompson

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