From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID, WEIRD_QUOTING autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,97a0fb5b3a5bcf2f X-Google-Attributes: gid103376,public From: "David C. Hoos, Sr." Subject: Re: Passing a Command to Unix in Ada Date: 1999/02/09 Message-ID: <79ptgi$e5a@hobbes.crc.com>#1/1 X-Deja-AN: 442495985 References: <36BCB222.EF9B4FF7@physics.BLAH.purdue.BLAH.edu> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Organization: Coleman Research Corporation Newsgroups: comp.lang.ada Date: 1999-02-09T00:00:00+00:00 List-Id: 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 ----