NSTask executed only once

Posted by Eimantas on Stack Overflow See other posts from Stack Overflow or by Eimantas
Published on 2010-05-17T04:55:27Z Indexed on 2010/05/17 5:00 UTC
Read the original article Hit count: 289

Filed under:
|

I'm having trouble executing different NSTask's. Same launchPath, different arguments. I have a class who's instances administer own NSTask objects and depending on arguments those instances were initialized with - dependent NSTask object is being created. I have two initializers:

// Method for finished task
- (void)taskFinished:(NSNotification *)aNotification {
  [myTask release];
  myTask = nil;

  [self createTask];
}

// Designated initializer
- (id) init {
  self = [super init];
  if (self != nil) {
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(taskFinished:)
                                                 name:NSTaskDidTerminateNotification 
                                               object:nil];
    [self createTask];
  }
  return self;
}

// Convenience initializer
- (id)initWithCommand:(NSString *)subCommand {
  self = [self init];
  if (self)
  {
    [self setCommand:subCommand];
  }
  return self;
}

And here 's the createTask method:

- (void)createTask {
  // myTask is a property defined as NSTask*
  myTask = [[NSTask alloc] init];
  [myTask setLaunchPath:@"/usr/bin/executable"];
}

Say I have 3 buttons. Each one creates different class instance with different NSTask objects. But problem is that only first one gets executed. The second ones does not even triger "click" event (via target-action). I think it could be cause of launchPath I'm trying to use, 'cause simple /bin/ls works fine. The same command in terminal has 0 return value (i.e. all is fine). Any guides or gotchas are much appreciated.

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about nstask