--  exec1.adb
--    Purpose: Shows how easy it is for a program to run a program.

with
  Ada.Text_IO,
  Interfaces.C.Strings,
  System,
  Unchecked_Conversion;

procedure Exec1 is
   use
     Ada.Text_IO,
     Interfaces.C,
     Interfaces.C.Strings;

   type chars_ptr_ptr is access constant chars_ptr;
   pragma Convention (C, chars_ptr_ptr);
   function To_Ptr is new Unchecked_Conversion (System.Address, chars_ptr_ptr);

   procedure execvp (path : in chars_ptr;
                     argv : in chars_ptr_ptr);
   pragma Import (C, execvp, "execvp");

   Arguments : constant chars_ptr_array (0 .. 2) :=
     (0 => New_String ("ls"),
      1 => New_String ("-l"),
      2 => Null_Ptr);
begin
   Put_Line ("* * * About to exec ls -l");
   execvp (path => Arguments (0),
           argv => To_Ptr (Arguments'Address));
   Put_Line ("* * * ls is done. bye");
end Exec1;

