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.
How to know directory where an executable was launched from in OS/X?
質問
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?
解決
所属していません StackOverflow