I have a console program which is linked to the Foundation framework on Mac. How do I find out the folder the executable is in?
The executable is not in a bundle. It is a standalone mach executable.
Nick Brooks
2010-07-28 17:04:57
A:
The first argument passed to main() ( argv[0]
) is the path to the executable itself. If you wrote said console program, you could get it that way.
Joshua Nozzi
2010-07-28 17:18:05
Only if you invoke the program by full path. If you put the program somewhere along your PATH (say, by installing it), then run it by name alone, `argv[0]` will be only the name.
Peter Hosey
2010-07-29 05:50:49
Hmmm. I thought under BSD it was always the full path. I'm not sure where I read that and can't find any reference to it, so I suppose it was merely an assumption on my part. Good to know.
Joshua Nozzi
2010-07-29 14:24:48
+4
A:
Even though the tool is not in a bundle, you can still use some of the NSBundle
methods. For example:
NSString * binaryPath = [[NSBundle mainBundle] executablePath];
NSString * executableFolder = [binaryPath stringByDeletingLastPathComponent];
Dave DeLong
2010-07-28 17:25:55