Starting a command line application
Starting a command line application
- Subject: Starting a command line application
- From: Patrick Machielse <email@hidden>
- Date: Thu, 15 Jul 2004 13:37:53 +0200
I want to start a command line program (deamon) from my Cocoa app. It seems
there are a lot of ways to do this. I found at least four:
- (void)startDeamon
{
NSString *execPath = @"path/to/executable";
NSString *execName = [execPath lastPathComponent];
// (1) LaunchServices
NSURL *deamonURL = [NSURL fileURLWithPath:execPath];
LSOpenCFURLRef((CFURLRef)deamonURL, NULL);
// (2) use system()
NSString *command = [execPath stringByAppendingString:@"&"];
system([command fileSystemRepresentation]);
// (3) the unix solution
if ( fork() == 0 ) {
// in child
const char *path = [execPath fileSystemRepresentation];
const char *name = [execName fileSystemRepresentation];
execl(path, name, NULL);
}
// (4) NSTask one liner
[NSTask launchedTaskWithLaunchPath:execPath arguments:[NSArray array]];
// not sure about 'arguments' here...
}
Can anyone shed some light on the relative merits of these alternatives. Are
there any side effects I should be aware of?
Patrick
---
Hieper Software
w: www.hieper.nl
e: email@hidden
_______________________________________________
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.