Question

When a C program written in the conventional int main(int argc, char* argv[]) style is launched from the Finder, it starts in the home directory of the user who launched it. (e.g. /Users/Fork).

Is there any fancy hook by which such a terminal-based program can know what directory it was launched in?

Était-ce utile?

La solution

You can obtain the full path for the program's binary image via _NSGetExecutablePath. Canonicalise that using e.g. realpath and then strip off the filename using e.g. dirname and you have the directory the program was started from.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top