comp.lang.ada
 help / color / mirror / Atom feed
* How to get pathname of executable
@ 2005-12-13 14:40 Dirk Heinrichs
  2005-12-13 15:26 ` Marc A. Criley
  0 siblings, 1 reply; 11+ messages in thread
From: Dirk Heinrichs @ 2005-12-13 14:40 UTC (permalink / raw)


Hello,

I'm trying to find out how to get the complete pathname of an ada executable
on Linux. I already tried Ada.Command_Line.Command_Name, but that only
gives the executable's name as the user typed it. I want to find out where
it is stored in the filesystem so that it can load other files from
directories relative to its own directory.

Thanx...

        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



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to get pathname of executable
  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
  0 siblings, 1 reply; 11+ messages in thread
From: Marc A. Criley @ 2005-12-13 15:26 UTC (permalink / raw)


Dirk Heinrichs wrote:
> Hello,
> 
> I'm trying to find out how to get the complete pathname of an ada executable
> on Linux. I already tried Ada.Command_Line.Command_Name, but that only
> gives the executable's name as the user typed it. I want to find out where
> it is stored in the filesystem so that it can load other files from
> directories relative to its own directory.

If you don't mind using vendor-supplied packages, and you're using GNAT, 
look at GNAT.OS_Lib.Normalize_Pathname(). Using this in combination with 
knowing what your current directory is, and/or 
GNAT.OS_Lib.Locate_Exec_On_Path() (if that might be needed), you can get 
that path.

-- Marc A. Criley
-- McKae Technologies
-- www.mckae.com
-- DTraq - XPath In Ada - XML EZ Out



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to get pathname of executable
  2005-12-13 15:26 ` Marc A. Criley
@ 2005-12-13 15:57   ` Dirk Heinrichs
  2005-12-14  6:34     ` Lionel Draghi
  0 siblings, 1 reply; 11+ messages in thread
From: Dirk Heinrichs @ 2005-12-13 15:57 UTC (permalink / raw)


Marc A. Criley wrote:

> Dirk Heinrichs wrote:
>> I'm trying to find out how to get the complete pathname of an ada
>> executable on Linux. I already tried Ada.Command_Line.Command_Name, but
>> that only gives the executable's name as the user typed it. I want to
>> find out where it is stored in the filesystem so that it can load other
>> files from directories relative to its own directory.
> 
> If you don't mind using vendor-supplied packages, and you're using GNAT,
> look at GNAT.OS_Lib.Normalize_Pathname(). Using this in combination with
> knowing what your current directory is, and/or
> GNAT.OS_Lib.Locate_Exec_On_Path() (if that might be needed), you can get
> that path.

That's what I was looking for.

Thanx...

        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



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to get pathname of executable
  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
  0 siblings, 2 replies; 11+ messages in thread
From: Lionel Draghi @ 2005-12-14  6:34 UTC (permalink / raw)


Dirk Heinrichs a ï¿œcrit :
> Marc A. Criley wrote:
> 
> 
>>Dirk Heinrichs wrote:
>>
>>>I'm trying to find out how to get the complete pathname of an ada
>>>executable on Linux. I already tried Ada.Command_Line.Command_Name, but
>>>that only gives the executable's name as the user typed it. I want to
>>>find out where it is stored in the filesystem so that it can load other
>>>files from directories relative to its own directory.
>>
>>If you don't mind using vendor-supplied packages, and you're using GNAT,
>>look at GNAT.OS_Lib.Normalize_Pathname(). Using this in combination with
>>knowing what your current directory is, and/or
>>GNAT.OS_Lib.Locate_Exec_On_Path() (if that might be needed), you can get
>>that path.
> 

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)

(Warning, I did not check this code)

-- 
Lionel Draghi



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to get pathname of executable
  2005-12-14  6:34     ` Lionel Draghi
@ 2005-12-15  0:06       ` Randy Brukardt
  2005-12-15  9:30       ` Dirk Heinrichs
  1 sibling, 0 replies; 11+ messages in thread
From: Randy Brukardt @ 2005-12-15  0:06 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1569 bytes --]

"Lionel Draghi" <Lionel.nospam.Draghi@Ada-France.org> wrote in message
news:439fbcd3$0$19908$626a54ce@news.free.fr...
> Dirk Heinrichs a �crit :
> > Marc A. Criley wrote:
> >
> >
> >>Dirk Heinrichs wrote:
> >>
> >>>I'm trying to find out how to get the complete pathname of an ada
> >>>executable on Linux. I already tried Ada.Command_Line.Command_Name, but
> >>>that only gives the executable's name as the user typed it. I want to
> >>>find out where it is stored in the filesystem so that it can load other
> >>>files from directories relative to its own directory.
...
>
> 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)
>
> (Warning, I did not check this code)

And if you want the full name of the directory, you need to use both:

     Ada.Directories.Full_Name (Ada.Directories.Containing_Directory
(Ada.Command_Line.Command_Name))

If your compiler supports this new package, it's recommended to use it
rather than implemented-defined packages, simply because it will make your
code more portable in the long run, and no less portable in the short run
(if some other compiler doesn't support Ada.Directories, then you might have
to change the code, but that other compiler is rather unlikely to support
GNAT-specific packages anyway, so this is no worse and likely better).

                     Randy.









^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to get pathname of executable
  2005-12-14  6:34     ` Lionel Draghi
  2005-12-15  0:06       ` Randy Brukardt
@ 2005-12-15  9:30       ` Dirk Heinrichs
  2005-12-15 10:26         ` Martin Dowie
  1 sibling, 1 reply; 11+ messages in thread
From: Dirk Heinrichs @ 2005-12-15  9:30 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to get pathname of executable
  2005-12-15  9:30       ` Dirk Heinrichs
@ 2005-12-15 10:26         ` Martin Dowie
  2005-12-15 13:10           ` Dirk Heinrichs
  0 siblings, 1 reply; 11+ messages in thread
From: Martin Dowie @ 2005-12-15 10:26 UTC (permalink / raw)


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

Ugh?

with Ada.Command_Line; use Ada.Command_Line;
with Ada.Directories;  use Ada.Directories;
with Ada.Text_IO;      use Ada.Text_IO;

procedure Test_Exe_Loc is
begin
   Put_Line (Full_Name (Containing_Directory (Command_Name)));
end Test_Exe_Loc;

C:\Ada\Temp>test_exe_loc
c:\ada\temp

C:\Ada\Temp>gnat -v
GNAT GPL 2005 (20050729)
...







^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to get pathname of executable
  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
  0 siblings, 2 replies; 11+ messages in thread
From: Dirk Heinrichs @ 2005-12-15 13:10 UTC (permalink / raw)


Martin Dowie wrote:

> Dirk Heinrichs wrote:
>> The GNAT GPL edition doesn't provide this, yet. But as soon as it
>> does, I will use it.
> 
> Ugh?
> 
> C:\Ada\Temp>gnat -v
> GNAT GPL 2005 (20050729)
> ...

Correction, then: My version of the GNAT GPL edition doesn't provide it:

$ gnat
GNAT 3.4.3 Copyright 1996-2004 Free Software Foundation, Inc.

Thanks for the hint, will see if I can upgrade.

Bye...

        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



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to get pathname of executable
  2005-12-15 13:10           ` Dirk Heinrichs
@ 2005-12-15 17:34             ` Pascal Obry
  2005-12-15 22:42             ` Simon Wright
  1 sibling, 0 replies; 11+ messages in thread
From: Pascal Obry @ 2005-12-15 17:34 UTC (permalink / raw)
  To: Dirk Heinrichs

Dirk,

> Correction, then: My version of the GNAT GPL edition doesn't provide it:
> 
> $ gnat
> GNAT 3.4.3 Copyright 1996-2004 Free Software Foundation, Inc.

This is *not* GNAT GPL. This is the GNAT version from the FSF.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to get pathname of executable
  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
  1 sibling, 1 reply; 11+ messages in thread
From: Simon Wright @ 2005-12-15 22:42 UTC (permalink / raw)


Dirk Heinrichs <ext-dirk.heinrichs@nokia.com> writes:

> $ gnat
> GNAT 3.4.3 Copyright 1996-2004 Free Software Foundation, Inc.

The FSF 4.0.0 version also compiles Martin's code -- with a warning:

   grendel:~/tmp simon$ gnatmake test_exe_loc     
   gcc -c test_exe_loc.adb
   test_exe_loc.adb:2:09: warning: "Ada.Directories" is an Ada 2005 unit
   gnatbind -x test_exe_loc.ali
   gnatlink test_exe_loc.ali
   grendel:~/tmp simon$ ./test_exe_loc 
   /Users/simon/tmp



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to get pathname of executable
  2005-12-15 22:42             ` Simon Wright
@ 2005-12-16  6:56               ` Martin Dowie
  0 siblings, 0 replies; 11+ messages in thread
From: Martin Dowie @ 2005-12-16  6:56 UTC (permalink / raw)


Simon Wright wrote:
> Dirk Heinrichs <ext-dirk.heinrichs@nokia.com> writes:
> 
> 
>>$ gnat
>>GNAT 3.4.3 Copyright 1996-2004 Free Software Foundation, Inc.
> 
> 
> The FSF 4.0.0 version also compiles Martin's code -- with a warning:
> 
>    grendel:~/tmp simon$ gnatmake test_exe_loc     
>    gcc -c test_exe_loc.adb
>    test_exe_loc.adb:2:09: warning: "Ada.Directories" is an Ada 2005 unit
>    gnatbind -x test_exe_loc.ali
>    gnatlink test_exe_loc.ali
>    grendel:~/tmp simon$ ./test_exe_loc 
>    /Users/simon/tmp

try "gnatmake -gnat05 ..."

Cheers

-- Martin



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2005-12-16  6:56 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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