comp.lang.ada
 help / color / mirror / Atom feed
From: Dirk Heinrichs <ext-dirk.heinrichs@nokia.com>
Subject: Re: How to get pathname of executable
Date: Thu, 15 Dec 2005 09:30:09 GMT
Date: 2005-12-15T09:30:09+00:00	[thread overview]
Message-ID: <BIaof.16750$Nb2.297057@news1.nokia.com> (raw)
In-Reply-To: 439fbcd3$0$19908$626a54ce@news.free.fr

Lionel Draghi wrote:

> If using vendor specifics is a problem, and if your compiler provides
> Ada 05 extensions, you may try:
>     Ada.Directories.Full_Name (Ada.Command_Line.Command_Name)
> 
> And if you're only interested in the directory:
>     Ada.Directories.Containing_Directory (Ada.Command_Line.Command_Name)

The GNAT GPL edition doesn't provide this, yet. But as soon as it does, I
will use it.

In the meantime, I use this code (UStrings is taken from the Lovelace
tutorial):

with UStrings;
with GNAT.OS_Lib;
with GNAT.Directory_Operations;
use UStrings, GNAT.OS_Lib, GNAT.Directory_Operations;

function Get_Exec_Path(Exec_Name : String) return UString is
   Me : UString := "";
   Current_Dir : String := Get_Current_Dir;
begin
   -- If Exec_name is an absolut path -> ready
   if Is_Absolute_Path(Exec_Name) then
      Me := U(Exec_Name);
   else
      -- Normalize current dir + Exec_name and see if the result
      -- is a regular file
      Me := U(Normalize_Pathname(Current_Dir & "/" & Exec_Name,
Resolve_Links=>False));
      if not Is_Regular_File(S(Me)) then
         -- Last chance: locate it on $PATH
         Me := U(Locate_Exec_On_Path(Exec_Name).all);
      end if;
   end if;
   return Me;
end Get_Exec_Path;

I call this function with Ada.Command_Line.Command_Name as input parameter.

Only thing left is to get the directory part out of this, but that shouldn't
be so hard.

Thanks a lot...

        Dirk
-- 
Dirk Heinrichs          | Tel:  +49 (0)162 234 3408
Configuration Manager   | Fax:  +49 (0)211 47068 111
Capgemini Deutschland   | Mail: dirk.heinrichs@capgemini.com
Hambornerstra�e 55      | Web:  http://www.capgemini.com
D-40472 D�sseldorf      | ICQ#: 110037733
GPG Public Key C2E467BB | Keyserver: www.keyserver.net



  parent reply	other threads:[~2005-12-15  9:30 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-13 14:40 How to get pathname of executable Dirk Heinrichs
2005-12-13 15:26 ` Marc A. Criley
2005-12-13 15:57   ` Dirk Heinrichs
2005-12-14  6:34     ` Lionel Draghi
2005-12-15  0:06       ` Randy Brukardt
2005-12-15  9:30       ` Dirk Heinrichs [this message]
2005-12-15 10:26         ` Martin Dowie
2005-12-15 13:10           ` Dirk Heinrichs
2005-12-15 17:34             ` Pascal Obry
2005-12-15 22:42             ` Simon Wright
2005-12-16  6:56               ` Martin Dowie
replies disabled

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