NSTask and Notification?
NSTask and Notification?
- Subject: NSTask and Notification?
- From: David Dauer <email@hidden>
- Date: Tue, 21 Oct 2003 21:33:16 +0200
Hello,
I'm creating an NSTask:
- (void)blah
{
theTask = [[NSTask alloc] init];
NSMutableArray *theArguments = [NSMutableArray array];
[theArguments addObject:@"-123"];
[theTask setStandardOutput:[NSPipe pipe]];
[theTask setArguments:theArguments];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(getOutput:) name: NSFileHandleReadCompletionNotification
object: [[theTask standardOutput] fileHandleForReading]];
[[[theTask standardOutput] fileHandleForReading]
readInBackgroundAndNotify];
[theTask setLaunchPath:path];
[theTask launch];
}
- (void)getOutput:(NSNotification *)aNotification
{
NSFileHandle *fh = (NSFileHandle *)[aNotification object];
NSData *data = [[aNotification userInfo]
objectForKey:NSFileHandleNotificationDataItem];
NSString *theOutput;
if ([data length]) {
theOutput = [[NSString alloc] initWith
Data:data
encoding:NSISOLatin1StringEncoding];
if (fh == [[theTask standardOutput] fileHandleForReading]) {
NSRunAlertPanel(@"alert", theOutput , @"OK", nil, nil);
} else {
return;
}
[theOutput release];
[[aNotification object] readInBackgroundAndNotify];
}
}
Seems to work fine, but i get the alert message 5 times whatever i'm doing.
Anyone knows what I'm doing wrong?
Thanks
David
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.