NSTask in NSOperation
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