• 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
NSTask in NSOperation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTask in NSOperation


  • Subject: NSTask in NSOperation
  • From: Kunal Parmar <email@hidden>
  • Date: Thu, 30 Sep 2010 20:26:56 -0700

I am using a NSTask in NSOperation. But I am not getting any notifications.
Here's the code:


- (void)start
{
    if ([self isCancelled])
    {
        // Move the operation to the finished state if it is canceled.
        [self willChangeValueForKey:@"isFinished"];
        finished = YES;
        [self didChangeValueForKey:@"isFinished"];
        return;
    }

    [self setTask:[[NSTask new] autorelease]];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector
(taskDidTerminate:)

name:NSTaskDidTerminateNotification
                                               object:[self task]];

    [[self task] setLaunchPath:@"/bin/ls"];
    [[self task] setArguments:[NSArray arrayWithObjects:@"-l", @"/", nil]];

    [[self task] setStandardOutput:[NSPipe pipe]];
    [[self task] setStandardError:[[self task] standardOutput]];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector
(dataAvailable:)

name:NSFileHandleReadCompletionNotification
                                               object:[[[self task]
standardOutput] fileHandleForReading]];
    [[[[self task] standardOutput] fileHandleForReading]
readInBackgroundAndNotify];

    [self willChangeValueForKey:@"isExecuting"];
    [[self task] launch];
    executing = YES;
    [self didChangeValueForKey:@"isExecuting"];
}


- (void)dataAvailable:(NSNotification *)notification
{
    NSLog(@"Data available");
}

- (void)taskDidTerminate:(NSNotification *)notification
{
    NSLog(@"Task terminated\n");
}


I tried using both +[NSOperationQueue mainQueue] as well as a newly created
operation queue. But no notifications are firing.

Thanks,
--
Kunal
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSTask in NSOperation
      • From: Kyle Sluder <email@hidden>
  • Prev by Date: Re: Changing classes
  • Next by Date: NSMenuItem enabling
  • Previous by thread: Re: Changing classes
  • Next by thread: Re: NSTask in NSOperation
  • Index(es):
    • Date
    • Thread