• 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: David Dauer <email@hidden>
  • Date: Wed, 22 Oct 2003 10:36:25 +0200

"Sailesh Agrawal" <email@hidden> schrieb am 21.10.2003 22:40 Uhr :

> 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
>


Ok. I'm doing now:

theTask = [[NSTask alloc] init];
NSPipe *pipe = [NSPipe pipe];
toolStdout = [[pipe fileHandleForReading] retain];

[theArguments addObject:@"-123"];

[theTask setStandardOutput:pipe];
[theTask setArguments:theArguments];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(getOutput:)
name:
NSFileHandleReadCompletionNotification
object: toolStdout];


[theTask setLaunchPath:path];

[theTask launch];
[toolStdout readInBackgroundAndNotify];

- (void)getOutput:(NSNotification *)aNotification
{
NSData *data = [[aNotification userInfo]
objectForKey:NSFileHandleNotificationDataItem];
NSString *theOutput;
if ([data length]) {

theOutput = [[NSString alloc] initWithData:data
encoding:NSISOLatin1StringEncoding];

NSLog(theOutput);
[theOutput release];

[[NSNotificationCenter defaultCenter] removeObserver:self
name:[aNotification
name]
object:nil];
}
[toolStdout readInBackgroundAndNotify];
}

BUT, when the task put more than the allowed charters out (255?) i'll get
only the first ones. That's why i got 5 messages.
thanks
_______________________________________________
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.

References: 
 >Re: NSTask and Notification? (From: "Sailesh Agrawal" <email@hidden>)

  • Prev by Date: Re: Use of protocols (for DO) crashing gcc3
  • Next by Date: Re: Aqua-style custom views
  • Previous by thread: Re: NSTask and Notification?
  • Next by thread: Re: NSTask and Notification?
  • Index(es):
    • Date
    • Thread