NSTask setStandardOutput bug?
NSTask setStandardOutput bug?
- Subject: NSTask setStandardOutput bug?
- From: justin webster <email@hidden>
- Date: Fri, 21 Dec 2007 15:43:59 +1300
I have a problem with running this code more than 248 times.
It is a simplified version of my implementation which is based on an
example from cocoaDevCentral
http://cocoadevcentral.com/articles/000031.php
this is a loop for the sake of demonstrating the problem:
int l;
for(l=0; l< 250; l++){
NSLog(@"%d", l);
NSTask *ps=[[NSTask alloc] init];
NSPipe *pipe=[[NSPipe alloc] init];
NSFileHandle *handle;
[ps setLaunchPath:@"/bin/ps"];
[ps setArguments:[NSArray arrayWithObjects:@"-p", PID, @"-o" ,
@"pcpu", nil]];
[ps setStandardOutput:pipe];
handle=[pipe fileHandleForReading];
[ps launch];
NSString *string = [[NSString alloc] initWithData:[handle
readDataToEndOfFile] encoding:NSASCIIStringEncoding];
NSLog(string);
[ps release];
[pipe release];
}
where 'PID' is any valid process ID.
it invariably fails after the 248th iteration with the error:
[NSCFDictionary setObject:forKey:]: attempt to insert nil value
I narrowed the crash down to the setStandardOutput call.
I can only guess it is some kind of memory management issue but can't
see how.
if I comment out the '[ps launch]' line (and the two after it) it
does exactly 124 iterations before crashing.
any ideas?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden