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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to