Reputation: 118053
Say I have a command line C program which is currently executing, and I want to read a file or execute another binary in the same directory - how can I find out what directory that is?
Note that I'm not looking for the current working directory. The user may have invoked my original program in any of the following ways (and possibly others I don't know about).
Ideally I'm looking for something which will work on a unix system and windows via MinGW.
Upvotes: 2
Views: 913
Reputation: 10672
http://c-faq.com/osdep/exepath.html
According to the C FAQ it can't be done reliably
Finding current executable's path without /proc/self/exe
Upvotes: 2