質問

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?

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top