From: Thomas Wolf <t_wolf@angelfire.com>
Subject: Re: Exec shell command with GNAT
Date: Tue, 14 Jan 2003 09:58:24 +0100
Date: 2003-01-14T09:58:24+01:00 [thread overview]
Message-ID: <MPG.188def7c97db9f32989698@news.ip-plus.net> (raw)
In-Reply-To: mailman.1042480803.13226.comp.lang.ada@ada.eu.org
david.c.hoos.sr@ada95.com wrote:
> 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;
Yes, that's it. My own version looks similar:
with Interfaces.C;
function Execute (Command : in String) return Integer
is
function Run (Command : in Interfaces.C.char_array)
return Interfaces.C.int;
pragma Import (C, Run, "system");
begin -- Execute
return Integer (Run (Interfaces.C.To_C (Item => Command)));
end Execute;
No fiddling around with addresses needed, and the declaration of "Run"
doesn't depend on Interfaces.C.int and Integer being the same. Note
that the Ada standard guarantees that an in-parameter of an array of
some element_type is passed in a way compatible with an "element_type *"
in C. (I.e., the address of the first element is passed.)
--
-----------------------------------------------------------------
Thomas Wolf e-mail: t_wolf@angelfire.com
next prev parent reply other threads:[~2003-01-14 8:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-13 16:58 Exec shell command with GNAT JuK
2003-01-13 17:59 ` David C. Hoos
2003-01-14 8:58 ` Thomas Wolf [this message]
2003-01-14 12:15 ` David C. Hoos, Sr.
2003-01-14 15:41 ` Adrian Knoth
2003-01-14 10:34 ` Lutz Donnerhacke
2003-01-13 18:52 ` Per Sandbergs
2003-01-13 19:01 ` Jeffrey Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox