I have a class that iterates through all the subfolders of a given folder on OSX and sends a message to its delegate for each folder it finds.
For each folder found I want to run an NSTask
. So far so good. It's when I specify a terminationHandler
to the NSTask
that I run into problems.
This is the code:
-(void)crawler:(FTCFileSystemCrawler *)aCrawler
didFindFolder:(NSURL *)aURL
withName:(NSString *)aFileName
stop:(BOOL *)stop{
NSTask *task = [NSTask new];
task.launchPath = @"/usr/bin/say";
task.arguments = @[aFileName];
task.terminationHandler = ^(NSTask *aTask){
NSLog(@"Terminating!");
[self.tasks removeObject:aTask];
};
[self.tasks addObject:task];
[task launch];
//[task waitUntilExit];
}
This works fine, it after sending launch
to the NSTask
, I send waitUntilExit
. If I don't, the termination handler never runs.
What am I doing wrong?
PS Please keep in mind that this is just a simple example. I'm actually using this to identify git repos and run a command it it.