NSTask is executed only once

I am having trouble running different NSTask. One launchPath, another arguments. I have a class in which instances manage their own objects NSTaskand depending on the arguments that were initialized by these instances with the dependent NSTaskobject. 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 is the method createTask:

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

Actions are performed by 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]
}

, . "click" ( ). , launchPath, , /bin/ls . 0 (.. ). gotchas .

+3
2

... , NSTask ....

NSTask, . NSTask ; NSThread, . : , , , . , , , . .

NSTask . NSTask .

, ( ) . . NSTaskTermination .

... , - , ( ).

+1

, PyObjC, subprocess Python.. , . .

0

Source: https://habr.com/ru/post/1745729/


All Articles