The problem is the use of "waitUntilExit" the buffer is filling up.
Try something like this...
( You might have to clean some of it up :-) )
Tom
- (void)runTask:(NSDictionary *)patch
{
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath: @"/usr/sbin/softwareupdate"];
[task setArguments:[NSArray arrayWithObjects:@"-i", [patch objectForKey:@"patch_identifier"], nil]];
[task setEnvironment:[NSDictionary dictionaryWithObject:@"1" forKey:@"COMMAND_LINE_INSTALL"]];
NSPipe *install_pipe = [NSPipe pipe];
[task setStandardOutput: install_pipe];
[task setStandardError: install_pipe];
NSFileHandle *file = [install_pipe fileHandleForReading];
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(taskEnded:)
name: NSTaskDidTerminateNotification
object: file];
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(readFromTask:)
name: NSFileHandleDataAvailableNotification
object: file];
[file readInBackgroundAndNotify];
[task launch];
[task release];
}
- (void)readFromTask:(NSNotification *)aNotification
{
NSData *data = [[aNotification userInfo] objectForKey: NSFileHandleNotificationDataItem];
if ([data length]) {
/* Process data */
[[aNotification object] readInBackgroundAndNotify];
}
}
- (void)taskEnded:(NSNotification *)aNotification
{
// Task is full complete
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
Post by Colin SwelinNSPipe *pipes = [NSPipe pipe];
NSTask* patchInstall = [[NSTask alloc] init];
[patchInstall setStandardOutput: pipes];
NSFileHandle *file = [pipes fileHandleForReading];
[patchInstall launch];
NSData *data = [file readDataToEndOfFile];
[patchInstall waitUntilExit];
......
[patchInstall release];
So i'm waiting for the task to complete, then I do my thing with the results.
Thanks,
Colin
Hi Colin,
I would need to see your NSTask code, to really know. Are you using notifications as data becomes available or are you waiting until the task has completed?
Thanks,
tom
Post by Colin SwelinHi,
I"m currently using NSTask to execute softwareupdate to install patches, however, there's a few patches that seem to hang when trying to install. For example, the latest 10.6.6 update and a older iTunes patch, everything else seems to work perfectly fine.
Anyone have any clues to why this might happen? I've set the "COMMAND_LINE_INSTALL" environment variable to 1, so i'm a little confused to why this is happening.
Thanks._______________________________________________
MacOSX-dev mailing list
http://www.omnigroup.com/mailman/listinfo/macosx-dev