• 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 and Notification?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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] initWithData: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.

  • Follow-Ups:
    • Re: NSTask and Notification?
      • From: "Sailesh Agrawal" <email@hidden>
  • Prev by Date: RE: setting the increment of all steppers
  • Next by Date: Re: NSTask and Notification?
  • Previous by thread: Re: + (NSHost*) currentHost?
  • Next by thread: Re: NSTask and Notification?
  • Index(es):
    • Date
    • Thread