• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Starting a command line application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Prev by Date: Re: Dumping input to NSTask
  • Next by Date: Re: CGDisplayCapture question
  • Previous by thread: Calculating Size of NSShadow
  • Next by thread: NSDrawer Newbie
  • Index(es):
    • Date
    • Thread