From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: Passing a Command to Unix in Ada
Date: 1999/02/09
Date: 1999-02-09T00:00:00+00:00 [thread overview]
Message-ID: <79ptgi$e5a@hobbes.crc.com> (raw)
In-Reply-To: 36BCB222.EF9B4FF7@physics.BLAH.purdue.BLAH.edu
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 ----
prev parent reply other threads:[~1999-02-09 0:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Larry Kilgallen
1999-02-13 0:00 ` Lieven Marchand
1999-02-09 0:00 ` dennison
1999-02-19 0:00 ` Steven Hovater
1999-02-19 0:00 ` robert_dewar
1999-02-09 0:00 ` David C. Hoos, Sr. [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox