|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Path to the current running executable
I'd like to be able to get the path to the current working executable
(from inside it). Technically this is easy, I simply have to collapse: getcwd and argv[0] Well argv[0] comes in a little late, I'd like to have access to this information before the 'main' function is called. Is there a way to get the path to an executable (from inside it) ? Thanks -Mathieu |
|
#2
|
|||
|
|||
|
Path to the current running executable
>I'd like to be able to get the path to the current working executable
>(from inside it). *THE* path? Is that anything like pressing *THE* key on *THE* keyboard connected to *THE* computer? >Technically this is easy, I simply have to collapse: getcwd and >argv[0] That is unlikely to ever work. The executable is usually not in the current working directory, but is more likely in a system directory for executables (e.g. /bin or /usr/bin or $HME/bin ). UNIX/Posix shells search components of the environment variable PATH (colon-separated paths) for where to find executables. a UNIX/Posix system, argv[0] may be an arbitrary (and malicious!) string unrelated to any of the names of the executable. >Well argv[0] comes in a little late, I'd like to have access to this >information before the 'main' function is called. Is there a way to >get the path to an executable (from inside it) ? If there is even the slightest security interrest by evildoers in having you find the wrong executable, don't use argv[0] to find a program to execute. Isn't the "singleton pattern" something that makes the rather short-sighted assumption that there is only one of something, and more can't possibly exist? and only one database, and only one nameserver, and only one user, etc.? (There should at least be TEST and PRDUCTIN of just about any object.) |
![]() |
| Viewing: Web Development Archives > FAQs > C/C++ > Path to the current running executable |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|