Re: How to get application path
Re: How to get application path
- Subject: Re: How to get application path
- From: Vernon Williams <email@hidden>
- Date: Thu, 21 Jun 2007 10:18:47 -0500
Thursday, June 21, 2007, 9:55am
Some questions.
Any particular reason your program is not in some directory in your
$PATH
variable?
Are you trying to find the path to the application from within the
application
(which I would presume is in C++ by your comment)?
Or are you trying to find the path to an application from within
another application?
If you are trying to get the path to the application you are in, and it
is in
C or C++, argument 0 of main will give you the path it was run with,
which may be a full or partial path, depending on how it was run.
The following is a C example:
#include <stdio.h>
int main (int num_args, char * args [ ])
{
printf ("program path = '%s'\n", args [0]);
}
However, if your program is not in a directory your $PATH variable,
it will obviously have to be run with the full path to be able to find
it
(unless your $PATH contains ".", for the current directory, so that
an executable in your current directory can be found without having
a full explicit path).
Vernon Williams
On Jun 21, 2007, at 6:26 AM, Filippo Ignozza wrote:
thanks for your answer but the application i want to run is not in
PATH.
On 21 Jun 2007 at 7:28, Mark J. Reed wrote:
On 6/21/07, Filippo Ignozza <email@hidden> wrote:
is there an easy way to get using C++ the fullpath of an X11
Application?
Applications can live anywhere on disk. But in order to be runnable,
they have to be somewhere in the $PATH. The standard C library
includes a function to search the $PATH for an app and run it
(execvp), but I don't think there's one for finding the exe without
running it. I think for that you have to just loop through the
directories in getenv("PATH") and check for existence of the program
in each one. You can probably borrow code from the which command, or
any of the shells, or...
--
Mark J. Reed <email@hidden>
Ignozza Filippo
Digital Video S.p.a.
Tel +39 06 43599369
+39 06 4393578
Fax +39 06 43251588
E-mail email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
X11-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
X11-users mailing list (email@hidden)
This email sent to email@hidden