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

Re: NSTask and Notification?


  • Subject: Re: NSTask and Notification?
  • From: "Sailesh Agrawal" <email@hidden>
  • Date: Tue, 21 Oct 2003 16:40:56 -0400

One thing I don't understand, do you want the output all at once when the
process terminates or continuously ?? In the code below, getOutput gets
called each time the task flushes stdout. If you're only interested in
the final output then listen for the NSTaskDidTerminateNotification
notification instead of NSFileHandleReadCompletionNotification. Then
just do [[theTask standardOutput] readDataToEndOfFile].

Good luck !
Sailesh

On Tue, 21 Oct 2003 21:33:16 +0200, "David Dauer" <email@hidden>
said:
> 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.
_______________________________________________
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: "Alastair J.Houghton" <email@hidden>
    • Re: NSTask and Notification?
      • From: David Dauer <email@hidden>
References: 
 >NSTask and Notification? (From: David Dauer <email@hidden>)

  • Prev by Date: NSTask and Notification?
  • Next by Date: detecting a double click ahead of time
  • Previous by thread: NSTask and Notification?
  • Next by thread: Re: NSTask and Notification?
  • Index(es):
    • Date
    • Thread