Re: Finding the executable path in a foundation tool.
Re: Finding the executable path in a foundation tool.
- Subject: Re: Finding the executable path in a foundation tool.
- From: James Quick <email@hidden>
- Date: Tue, 8 Jul 2003 20:46:53 -0400
On Tuesday, July 8, 2003, at 06:21 PM, Prachi Gauriar wrote:
>
How about the old-fashioned C way of just looking at argv[0]?
>
Contents of main.m:
>
>
#import <Foundation/Foundation.h>
>
>
int main (int argc, const char * argv[]) {
>
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
>
NSString *executablePath = [NSString stringWithUTF8String:argv[0]];
>
>
NSLog(@"%@\n", executablePath);
>
>
[pool release];
>
return 0;
>
}
This will only work if the excutable was execed using a full path. A
partial pathname
may not work. You also need to examine each element in the environment
search
path. That, too, may fail in certain instances if the process has
changes its current
working directory.
The route to the answer was provided by Tom Harrington who referred me
to
the AuthSample project. There was a rather spooky function showing how
to break all the rules about hidden interfaces and relying
implementation details
which are out of one's control. It also made use of a Jaguar addition
_NSGetExecutablePath().
I need to find the the current executable on disk because the stab
entries are stuck
in the disk image, so I'll need to mmap() a section of the object on
disk to the running
process image.
Thanks to all who responded.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.