NSTask output reading problem
NSTask output reading problem
- Subject: NSTask output reading problem
- From: Jean Bovet <email@hidden>
- Date: Sat, 24 Apr 2004 12:20:29 +0200
Hello,
Currently developing an application to help localizing other
application, I am having sometime (that's the problem!) the following
problem: the output stream from the nibtool (launched using NSTask) is
not complete and then the property parser cannot decode it. I give you
below the portion of code I'm using to setup the output NSFileHandle,
to launch the task and to wait until it has terminated. Is there
something wrong ? Where could I miss some characters ?
Thank you in advance.
Jean
*** Code ***
- (void)run {
[mTaskData release];
mTaskData = [[NSMutableData alloc] init];
[mTaskErrorData release];
mTaskErrorData = [[NSMutableData alloc] init];
NSPipe *outputPipe = [NSPipe pipe];
NSFileHandle *taskOutput = [outputPipe fileHandleForReading];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(taskDataAvailable:)
name:NSFileHandleReadCompletionNotification object:taskOutput];
[task setStandardOutput:outputPipe];
NSPipe *errorPipe = [NSPipe pipe];
NSFileHandle *errorOutput = [errorPipe fileHandleForReading];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(taskErrorDataAvailable:)
name:NSFileHandleReadCompletionNotification object:errorOutput];
[task setStandardError:errorPipe];
[task launch];
[taskOutput readInBackgroundAndNotify];
[errorOutput readInBackgroundAndNotify];
[task waitUntilExit];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:NSFileHandleReadCompletionNotification object:taskOutput];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:NSFileHandleReadCompletionNotification object:errorOutput];
NSData *data = nil;
while((data = [taskOutput availableData]) && [data length]>0)
[mTaskData append
Data:data];
}
- (void)taskDataAvailable:(NSNotification*)notif
{
NSData *incomingData = [[notif userInfo]
objectForKey:NSFileHandleNotificationDataItem];
if (incomingData && [incomingData length]>0) {
// Note: if incomingData is nil, the filehandle is closed.
[mTaskData append
Data:incomingData];
[[notif object] readInBackgroundAndNotify]; // go back for
more.
}
}
_______________________________________________
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.