Re: NSTask and Notification?
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] initWith
Data: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.