tags:

views:

31

answers:

0

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"];
}

The actions are executed via selecting different rows in NSOutlineView (using PXSourceList as a wrapper):

- (void)sourceListSelectionDidChange:(NSNotification *)notification {
  id sourceList = [notification object];
  NSIndexSet *selection = [sourceList selectedRowIndexes];
  NSString *identifier = [[sourceList itemAtRow:[selection firstIndex]] identifier];

  // this way `/usr/bin/executable ${identifier}` is being created
  MyCommand *command = [[MyCommand alloc] initWithSubcommand:identifier];

  // this method executes [myTask launch];
  [command execute]
}

The problem is that only first one gets executed. The second ones does not even trigger "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.