• 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 output reading problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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 appendData: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 appendData: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.


  • Follow-Ups:
    • Re: NSTask output reading problem
      • From: Ondra Cada <email@hidden>
  • Prev by Date: Re: Programmatically creating NSButton
  • Next by Date: Re: command line tool output into a string?
  • Previous by thread: Accepting a proxy-icon drop
  • Next by thread: Re: NSTask output reading problem
  • Index(es):
    • Date
    • Thread