comp.lang.ada
 help / color / mirror / Atom feed
From: nickroberts@ukf.net (Nick Roberts)
Subject: Re: How to find directory where the program is?
Date: Wed, 24 Apr 2002 23:08:28 GMT
Date: 2002-04-24T23:08:28+00:00	[thread overview]
Message-ID: <3cc73115.426446486@news.cis.dfn.de> (raw)
In-Reply-To: 3CC6D15A.2070509@mail.com

On Wed, 24 Apr 2002 11:38:02 -0400, Hyman Rosen <hyrosen@mail.com> strongly
typed:

>Preben Randhol wrote:
>> How can one in Ada95 find out from which directory the Ada program is
>> stored in.  I mean I need to find out if my program is stored in
>> /usr/bin/ or /usr/local/bin or some other directory.
>
>There is no a priori reason for this to even be possible. Your Ada
>program could be loaded in PROM on your toaster, and even in UNIX,
>the same executable file could have many links to it in different
>directories, with different names.

Furthermore, one has to ask the question "why?" (Why do you wish your
program to discover its own executable?) As Hyman points out, there may not
be one (there may zero or several), but even if there is one, your program
may not have (any) access permission to it. (Side Issue 1, see below.)
Actually, what kind of access would you require?

Side Issue 1. It may just be me, but I would suggest that (on a well
managed system ;-) the vast majority of Ada programs will not need to, and
should not, have any access to their own executables. (If you're wondering
why, think about how viruses propagate themselves.)

If your program is, say, a discombobulator, and supposing it needs to add
itself to a cron-list (or equivalent), in order to complete one of its
actions perhaps, I would suggest you: (a) try to find a program argument
named say "-phase2" and use the value of the argument following it; (b) if
that fails, get the value of the environment variable named say
"discombob2"; (c) if that fails, use whatever strategy you do to obtain the
program's configuration file, and search for a line there beginning with
"phase2=" and use the remainder of the line; (d) if that fails, obtain the
configuration file's directory D and use D & Ada.Command_Line.Command_Name;
(e) if that fails, use D & Default_Program_File_Name (which you have
defined, e.g. a function which returns "discombob" under UNIX systems and
"DISCOMB.EXE" under DOS/Windows). (Simple ;-) Your program installer should
generate a configuration file with e.g.
"phase1=C:\SUPASOFT\BOBULTNS\DISCOMB.EXE" and
"phase2=C:\SUPASOFT\BOBULTNS\DISCOMB.EXE" in it, so that your program is
spared the effort (and hit-and-miss qualities) of trying to find out the
incantation necessary to run itself, and so that users are given maximum
flexibility in managing their system.

Hope this post has some element of enlightening qualities. (Not really sure
if it does; that's how posts go sometimes :-)

-- 
Nick Roberts



  parent reply	other threads:[~2002-04-24 23:08 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-23 18:28 How to find directory where the program is? Preben Randhol
2002-04-23 19:10 ` Florian Weimer
2002-04-23 19:37 ` Randy Brukardt
2002-04-23 20:53   ` Preben Randhol
2002-04-23 21:04 ` Joachim Schr�er
2002-04-24  8:35 ` Thierry Lelegard
2002-04-24  8:43 ` Jean-Pierre Rosen
2002-04-24 10:33   ` Preben Randhol
2002-04-24 11:43     ` Jean-Pierre Rosen
2002-04-24 14:44       ` Preben Randhol
2002-04-24 15:38 ` Hyman Rosen
2002-04-24 17:44   ` Preben Randhol
2002-04-24 23:08   ` Nick Roberts [this message]
2002-04-25  7:28     ` Preben Randhol
2002-04-25 14:18       ` Marin David Condic
2002-04-26 16:24         ` Stephen Leake
2002-04-26 20:41           ` achrist
2002-04-26 21:31           ` Larry Kilgallen
2002-04-29 15:38           ` Marin David Condic
2002-04-25 17:10       ` Sergey Koshcheyev
2002-04-25 21:11         ` Nick Roberts
2002-04-25 23:28           ` Sergey Koshcheyev
2002-04-26  5:57             ` Preben Randhol
2002-04-26 16:22           ` Stephen Leake
2002-04-26 17:13         ` Anders Gidenstam
2002-04-26 12:18       ` Jacob Sparre Andersen
2002-04-26 12:23         ` Preben Randhol
2002-04-26 12:48           ` David C. Hoos
2002-04-26 14:13             ` Preben Randhol
2002-04-27  8:18               ` Eric G. Miller
2002-04-26 13:09         ` Marin David Condic
2002-04-27 14:39           ` Larry Kilgallen
2002-04-27 21:12             ` Nick Roberts
2002-04-29 15:52             ` Marin David Condic
2002-04-24 17:44 ` Egil Harald Hoevik
  -- strict thread matches above, loose matches on Subject: below --
2002-04-23 19:24 Beard, Frank [Contractor]
2002-04-23 19:56 Beard, Frank [Contractor]
2002-04-23 22:41 ` Larry Kilgallen
2002-04-23 23:28 Beard, Frank [Contractor]
2002-04-24  0:49 ` Larry Kilgallen
2002-04-24  2:31   ` achrist
2002-04-24 10:29     ` Preben Randhol
2002-04-24 15:28       ` Darren New
2002-04-24 17:43         ` Preben Randhol
2002-04-24 18:33           ` Randy Brukardt
2002-04-24 21:00             ` Wes Groleau
2002-04-25 19:26               ` Randy Brukardt
2002-04-25  2:37             ` Steve Doiel
2002-04-25  7:26               ` Preben Randhol
2002-04-24  9:44 Grein, Christoph
2002-04-25 10:35 ` Thierry Lelegard
2002-04-25 19:30   ` Philippe Waroquiers
2002-04-25 22:57     ` Larry Kilgallen
2002-04-25 16:43 Beard, Frank [Contractor]
replies disabled

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