C/C++
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   Web Development Archives FAQs C/C++

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Web Development Archives Sponsor:
  #1  
Old June 25th, 2008, 09:09 AM
mathieu
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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

Reply With Quote
  #2  
Old July 4th, 2008, 05:00 PM
Gordon Burditt
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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.)


Reply With Quote
Reply

Viewing: Web Development Archives FAQs C/C++ > Path to the current running executable


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT