comp.lang.ada
 help / color / mirror / Atom feed
* Passing a Command to Unix in Ada
@ 1999-02-06  0:00 Robert T. Sagris
  1999-02-07  0:00 ` Thomas Preymesser
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Robert T. Sagris @ 1999-02-06  0:00 UTC (permalink / raw)


I was wondering if there are any functions similar to the system 
command in C available in Ada. Also I was wondering if there was 
a similar function as rename in Ada.

If you could give a translation for the following lines it would be
most appreciated. *THIS IS NOT HOMEWORK* I am trying to rewrite a little
program I wrote in C to Ada but don't no were to look. I have looked
through Ada, as a Second Language by Cohen and found nothing
useful for this problem

Well here are the lines.

/*The Header files for the functions*/
#include <stdio.h>
#include <stdlib.h>

main() {
...

/* In particular how would I cobble together some arbitrary string
   made up of string and integer variables. */
sprintf(command, "ls *%i.%s", some_integer, some_string);

/* Is there some equivalent command available in Ada's standard
   packages? */
system(command);

/* I know of the file handling functions in Ada.Text_IO such as
   Create, Open, Close, Delete etc.. but no Rename. (Is there on?)
*/
rename(old_file_name_string, new_file_name_string);

}

Well I hope this doesn't seem to simplistic but I found if I am
to general in my questions I get answer that assume I know more
about programming in Ada than I do.

Well thanks for any help you can give me.

Robbi Sagris




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

* Re: Passing a Command to Unix in Ada
  1999-02-06  0:00 Passing a Command to Unix in Ada Robert T. Sagris
@ 1999-02-07  0:00 ` Thomas Preymesser
  1999-02-08  0:00 ` dennison
  1999-02-09  0:00 ` David C. Hoos, Sr.
  2 siblings, 0 replies; 11+ messages in thread
From: Thomas Preymesser @ 1999-02-07  0:00 UTC (permalink / raw)


Hi Robert,

On Sat, 06 Feb 1999 16:20:34 -0500, "Robert T. Sagris"
<robs@physics.BLAH.purdue.BLAH.edu> wrote:

>I was wondering if there are any functions similar to the system 
>command in C available in Ada. 

there's an example at my Ada-page at: 

	<http://www.geocities.com/SiliconValley/Park/6549/>


-- 
-- phone/phax:  +49-911-811957              mobile: +49-172-8111959
-- Bureau mail: Thomas.Preymesser@mblf.de   phone:  +49-711-2574-508
-- WWW:         http://www.geocities.com/Hollywood/3033/
-- For my always up-to-date contact information, click here: http://www.planetall.com/main.asp?cid=1679268




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

* Re: Passing a Command to Unix in Ada
  1999-02-06  0:00 Passing a Command to Unix in Ada Robert T. Sagris
  1999-02-07  0:00 ` Thomas Preymesser
@ 1999-02-08  0:00 ` dennison
  1999-02-09  0:00   ` Robert T. Sagris
  1999-02-09  0:00 ` David C. Hoos, Sr.
  2 siblings, 1 reply; 11+ messages in thread
From: dennison @ 1999-02-08  0:00 UTC (permalink / raw)


In article <36BCB222.EF9B4FF7@physics.BLAH.purdue.BLAH.edu>,
  "Robert T. Sagris" <robs@physics.BLAH.purdue.BLAH.edu> wrote:
> I was wondering if there are any functions similar to the system
> command in C available in Ada. Also I was wondering if there was

(sigh.)

There is no "system" command in C. Many OS'es have a system call named
"system" that does what you describe, providing you link in the proper OS
library. OS routines can be used in Ada by declaring their subprogram
specification and following it up with a "pragma import" statement. Linking
in OS libraries is a compiler-specific thing; consult your compiler docs for
more information.

This is similar to C, except for the "pragma" part. C just *assumes* that any
function you declared but didn't complete will be linked in later. That makes
calling OS routines like "system" a bit simpler, but it also can cause
problems linking when the developer forgets to code a routine.

T.E.D.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Passing a Command to Unix in Ada
  1999-02-09  0:00     ` dennison
@ 1999-02-09  0:00       ` Larry Kilgallen
  1999-02-13  0:00         ` Lieven Marchand
  0 siblings, 1 reply; 11+ messages in thread
From: Larry Kilgallen @ 1999-02-09  0:00 UTC (permalink / raw)


In article <79q8n7$u00$1@nnrp1.dejanews.com>, dennison@telepath.com writes:

> A couple of folks have written to me to point out that "system", although not
> a proper statement like "break" and "for", is indeed required to exist for C
> implementations by the ANSI C standard. So I must apologize for causing any
> confusion there.

Does anybody know what this required call does on a Macintosh ?

Larry Kilgallen




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

* Re: Passing a Command to Unix in Ada
  1999-02-06  0:00 Passing a Command to Unix in Ada Robert T. Sagris
  1999-02-07  0:00 ` Thomas Preymesser
  1999-02-08  0:00 ` dennison
@ 1999-02-09  0:00 ` David C. Hoos, Sr.
  2 siblings, 0 replies; 11+ messages in thread
From: David C. Hoos, Sr. @ 1999-02-09  0:00 UTC (permalink / raw)



Robert T. Sagris wrote in message <36BCB222.EF9B4FF7@physics.BLAH.purdue.BLAH.edu>...
>I was wondering if there are any functions similar to the system
>command in C available in Ada. Also I was wondering if there was
>a similar function as rename in Ada.
>
>If you could give a translation for the following lines it would be
>most appreciated. *THIS IS NOT HOMEWORK* I am trying to rewrite a little
>program I wrote in C to Ada but don't no were to look. I have looked
>through Ada, as a Second Language by Cohen and found nothing
>useful for this problem
>

Here is a library function which interfaces to the C library "system" function, followed by a little test program to execute it.

This should serve to illustrate how to interface to _any_ C library function.

Strictly speaking, this technique does not "pass a command to Unix" -- rather it interfaces to the C library.  In the case of
Execute_Shell_Command which interfaces to the C "System" command, I gave it the name I did for two reasons, viz.:

    1.  The name "System" cannot be used in Ada for a
        user-defined entity, because it's a language-defined
        package.

    2.  The name Execute_Shell_Command is more descriptive
        of what it actually does.  In some contexts, a program
        which executes a shell command is considered a security
        risk, so I make what it's doing more obvious.

---- begin Ada source code ----
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;
with Ada.Command_Line;
with Ada.Text_Io;
with Execute_Shell_Command;
procedure Test_Execute_Shell_Command is
   Status : Integer;
begin
   Ada.Text_Io.Put_Line
     ("Program """ & Ada.Command_Line.Command_Name &
      """ is executing the shell command """ &
      Ada.Command_Line.Argument (1) & """");
   Status := Execute_Shell_Command (Ada.Command_Line.Argument (1));
   Ada.Text_Io.Put_Line
     ("Function "" Execute_Shell_Command"" returned" &
      Integer'Image (Status));
end Test_Execute_Shell_Command;
---- end Ada source code ----








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

* Re: Passing a Command to Unix in Ada
  1999-02-09  0:00   ` Robert T. Sagris
  1999-02-09  0:00     ` dennison
@ 1999-02-09  0:00     ` dennison
  1999-02-09  0:00       ` Larry Kilgallen
  1999-02-19  0:00     ` Steven Hovater
  2 siblings, 1 reply; 11+ messages in thread
From: dennison @ 1999-02-09  0:00 UTC (permalink / raw)


In article <36C06B04.3E2D7A1F@physics.BLAH.purdue.BLAH.edu>,
  "Robert T. Sagris" <robs@physics.BLAH.purdue.BLAH.edu> wrote:
> I'm sorry my terminology was a bit off when I wrote this.
> I meant the system function in stdlib.h.
> If its not in there I don't know how my c program should work.
> The only header file this program includes are stdio.h and stdlib.h.
> So, it would seem system and rename are not being called be a  OS
> specific libraries. Am misinterpreting the std part in stdlib as meaning
> STANDARD or am I confused.
>
> dennison@telepath.com wrote:
> >
> > In article <36BCB222.EF9B4FF7@physics.BLAH.purdue.BLAH.edu>,
> >   "Robert T. Sagris" <robs@physics.BLAH.purdue.BLAH.edu> wrote:
> > > I was wondering if there are any functions similar to the system
> > > command in C available in Ada. Also I was wondering if there was

> > There is no "system" command in C. Many OS'es have a system call named

A couple of folks have written to me to point out that "system", although not
a proper statement like "break" and "for", is indeed required to exist for C
implementations by the ANSI C standard. So I must apologize for causing any
confusion there.

But the point is that it is a library routine that should be callable from
any language that knows how to link to it, not a command unique to C that is
unavailable outside of it. On the Unix system I have access to it is located
in libc.a. Ada has a standard way of importing C routines. The trick is
linking to libc.a, which you will have to consult your compiler docs to
figure out how to do. If you have trouble figuring it out, post specifics
(compiler/Platform/OS) and someone here may be able to help out.


T.E.D.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Passing a Command to Unix in Ada
  1999-02-09  0:00   ` Robert T. Sagris
@ 1999-02-09  0:00     ` dennison
  1999-02-09  0:00     ` dennison
  1999-02-19  0:00     ` Steven Hovater
  2 siblings, 0 replies; 11+ messages in thread
From: dennison @ 1999-02-09  0:00 UTC (permalink / raw)


In article <36C06B04.3E2D7A1F@physics.BLAH.purdue.BLAH.edu>,
  "Robert T. Sagris" <robs@physics.BLAH.purdue.BLAH.edu> wrote:
> I'm sorry my terminology was a bit off when I wrote this.
> I meant the system function in stdlib.h.
> If its not in there I don't know how my c program should work.
> The only header file this program includes are stdio.h and stdlib.h.
> So, it would seem system and rename are not being called be a  OS
> specific libraries. Am misinterpreting the std part in stdlib as meaning
> STANDARD or am I confused.
>
> dennison@telepath.com wrote:
> >
> > In article <36BCB222.EF9B4FF7@physics.BLAH.purdue.BLAH.edu>,
> >   "Robert T. Sagris" <robs@physics.BLAH.purdue.BLAH.edu> wrote:
> > > I was wondering if there are any functions similar to the system
> > > command in C available in Ada. Also I was wondering if there was

> > There is no "system" command in C. Many OS'es have a system call named

A couple of folks have written to me to point out that "system", although not
a proper statement like "break" and "for", is indeed required to exist for C
implementations by the ANSI C standard. So I must apologize for causing any
confusion there.

But the point is that it is a library routine that should be callable from
any language that knows how to link to it, not a command unique to C that is
unavailable outside of it. On the Unix system I have access to it is located
in libc.a. Ada has a standard way of importing C routines. The trick is
linking to libc.a, which you will have to consult your compiler docs to
figure out how to do. If you have trouble figuring it out, post specifics
(compiler/Platform/OS) and someone here may be able to help out.

Also, some compiler implementations provide an interface to "system" out of
the box...


T.E.D.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Passing a Command to Unix in Ada
  1999-02-08  0:00 ` dennison
@ 1999-02-09  0:00   ` Robert T. Sagris
  1999-02-09  0:00     ` dennison
                       ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Robert T. Sagris @ 1999-02-09  0:00 UTC (permalink / raw)


I'm sorry my terminology was a bit off when I wrote this.
I meant the system function in stdlib.h.
If its not in there I don't know how my c program should work.
The only header file this program includes are stdio.h and stdlib.h.
So, it would seem system and rename are not being called be a  OS
specific libraries. Am misinterpreting the std part in stdlib as meaning
STANDARD or am I confused.

dennison@telepath.com wrote:
> 
> In article <36BCB222.EF9B4FF7@physics.BLAH.purdue.BLAH.edu>,
>   "Robert T. Sagris" <robs@physics.BLAH.purdue.BLAH.edu> wrote:
> > I was wondering if there are any functions similar to the system
> > command in C available in Ada. Also I was wondering if there was
> 
> (sigh.)
> 
> There is no "system" command in C. Many OS'es have a system call named
> "system" that does what you describe, providing you link in the proper OS
> library. OS routines can be used in Ada by declaring their subprogram
> specification and following it up with a "pragma import" statement. Linking
> in OS libraries is a compiler-specific thing; consult your compiler docs for
> more information.
> 
> This is similar to C, except for the "pragma" part. C just *assumes* that any
> function you declared but didn't complete will be linked in later. That makes
> calling OS routines like "system" a bit simpler, but it also can cause
> problems linking when the developer forgets to code a routine.
> 
> T.E.D.
> 
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own




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

* Re: Passing a Command to Unix in Ada
  1999-02-09  0:00       ` Larry Kilgallen
@ 1999-02-13  0:00         ` Lieven Marchand
  0 siblings, 0 replies; 11+ messages in thread
From: Lieven Marchand @ 1999-02-13  0:00 UTC (permalink / raw)


kilgallen@eisner.decus.org (Larry Kilgallen) writes:

> Does anybody know what this required call [system] does on a Macintosh ?
> 

Actually, ANSI C requires that there exists a function system() in the
library. system(NULL) should return whether it does something useful
on the platform. system(Arbitrary_String) is implementation
defined. So my first guess would be that on the Macintosh, system
systematically returns an error, which is a completely conformant
implementation.

-- 
Lieven Marchand <mal@bewoner.dma.be> 
------------------------------------------------------------------------------
Few people have a talent for constructive laziness. -- Lazarus Long




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

* Re: Passing a Command to Unix in Ada
  1999-02-09  0:00   ` Robert T. Sagris
  1999-02-09  0:00     ` dennison
  1999-02-09  0:00     ` dennison
@ 1999-02-19  0:00     ` Steven Hovater
  1999-02-19  0:00       ` robert_dewar
  2 siblings, 1 reply; 11+ messages in thread
From: Steven Hovater @ 1999-02-19  0:00 UTC (permalink / raw)


If you're using something like Apex, you can access the POSIX implementation to do
an exec etc. Let me know if you need sample code -

Cheers,
Steve


"Robert T. Sagris" wrote:

> I'm sorry my terminology was a bit off when I wrote this.
> I meant the system function in stdlib.h.
> If its not in there I don't know how my c program should work.
> The only header file this program includes are stdio.h and stdlib.h.
> So, it would seem system and rename are not being called be a  OS
> specific libraries. Am misinterpreting the std part in stdlib as meaning
> STANDARD or am I confused.
>
> dennison@telepath.com wrote:
> >
> > In article <36BCB222.EF9B4FF7@physics.BLAH.purdue.BLAH.edu>,
> >   "Robert T. Sagris" <robs@physics.BLAH.purdue.BLAH.edu> wrote:
> > > I was wondering if there are any functions similar to the system
> > > command in C available in Ada. Also I was wondering if there was
> >
> > (sigh.)
> >
> > There is no "system" command in C. Many OS'es have a system call named
> > "system" that does what you describe, providing you link in the proper OS
> > library. OS routines can be used in Ada by declaring their subprogram
> > specification and following it up with a "pragma import" statement. Linking
> > in OS libraries is a compiler-specific thing; consult your compiler docs for
> > more information.
> >
> > This is similar to C, except for the "pragma" part. C just *assumes* that any
> > function you declared but didn't complete will be linked in later. That makes
> > calling OS routines like "system" a bit simpler, but it also can cause
> > problems linking when the developer forgets to code a routine.
> >
> > T.E.D.
> >
> > -----------== Posted via Deja News, The Discussion Network ==----------
> > http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own

--
Steven Hovater
svh@rational.com
Software Engineering Consultant
Phone/fax:781-676-2565/2500
Rational Software
Pager: 888-906-2209
83 Hartwell Ave, Lexington, MA                                             Amateur
radio: AA1YH






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

* Re: Passing a Command to Unix in Ada
  1999-02-19  0:00     ` Steven Hovater
@ 1999-02-19  0:00       ` robert_dewar
  0 siblings, 0 replies; 11+ messages in thread
From: robert_dewar @ 1999-02-19  0:00 UTC (permalink / raw)


In article <36CDCC36.630D3811@mediaone.net>,
  Steven Hovater <nh-ho@mediaone.net> wrote:
> If you're using something like Apex, you can access the
> POSIX implementation to do an exec etc. Let me know if
> you need sample code -

You hardly need POSIX for this, just interface to the
standard exec function in the normal manner using pragma
Import.


-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

end of thread, other threads:[~1999-02-19  0:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-02-06  0:00 Passing a Command to Unix in Ada Robert T. Sagris
1999-02-07  0:00 ` Thomas Preymesser
1999-02-08  0:00 ` dennison
1999-02-09  0:00   ` Robert T. Sagris
1999-02-09  0:00     ` dennison
1999-02-09  0:00     ` dennison
1999-02-09  0:00       ` Larry Kilgallen
1999-02-13  0:00         ` Lieven Marchand
1999-02-19  0:00     ` Steven Hovater
1999-02-19  0:00       ` robert_dewar
1999-02-09  0:00 ` David C. Hoos, Sr.

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