Discussion:
Using NSTask to execute softwareupdate
Colin Swelin
2011-01-06 16:54:40 UTC
Permalink
Hi,

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.
Tom Jones
2011-01-08 17:48:53 UTC
Permalink
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 Swelin
Hi,
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
Colin Swelin
2011-01-08 17:59:08 UTC
Permalink
Here's the basic NSTask stuff:


NSPipe *pipes = [NSPipe pipe];
NSTask* patchInstall = [[NSTask alloc] init];
[patchInstall setLaunchPath:@
"/usr/sbin/softwareupdate"];
[patchInstall setArguments:[NSArray arrayWithObjects:@"-i", [patch
objectForKey:@"patch_identifier"], nil]];
[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
Post by Tom Jones
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 Swelin
Hi,
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.
Post by Colin Swelin
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.
Post by Colin Swelin
Thanks._______________________________________________
MacOSX-dev mailing list
http://www.omnigroup.com/mailman/listinfo/macosx-dev
Tom Jones
2011-01-08 18:27:36 UTC
Permalink
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 Swelin
NSPipe *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 Swelin
Hi,
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
Colin Swelin
2011-01-26 00:02:58 UTC
Permalink
Hi,

Sorry for the long reply. I gave this a try and it looked promising, however, the task still hangs at the "writing files" step of few patches. It's reading the buffer correctly, as its output everything up to that point.

Anyone have any insight to why the 10.6.6 update does this?

Thanks again,
Colin
Post by Tom Jones
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];
NSPipe *install_pipe = [NSPipe pipe];
[task setStandardOutput: install_pipe];
[task setStandardError: install_pipe];
NSFileHandle *file = [install_pipe fileHandleForReading];
[[NSNotificationCenter defaultCenter] addObserver: self
name: NSTaskDidTerminateNotification
object: file];
[[NSNotificationCenter defaultCenter] addObserver: self
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 Swelin
NSPipe *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 Swelin
Hi,
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
sunfire
2011-09-16 15:29:22 UTC
Permalink
Hi Colin,
I'm having the same issue and I have been unsuccessful in fixing it. Did you
ever resolve this?

Thanks,
Charles
Post by Colin Swelin
Hi,
Sorry for the long reply. I gave this a try and it looked promising,
however, the task still hangs at the "writing files" step of few patches.
It's reading the buffer correctly, as its output everything up to that
point.
Anyone have any insight to why the 10.6.6 update does this?
Thanks again,
Colin
Post by Tom Jones
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];
NSPipe *install_pipe = [NSPipe pipe];
[task setStandardOutput: install_pipe];
[task setStandardError: install_pipe];
NSFileHandle *file = [install_pipe fileHandleForReading];
[[NSNotificationCenter defaultCenter] addObserver: self
name: NSTaskDidTerminateNotification
object: file];
[[NSNotificationCenter defaultCenter] addObserver: self
name: NSFileHandleDataAvailableNotification
object: file];
[file readInBackgroundAndNotify];
[task launch];
[task release];
}
- (void)readFromTask:(NSNotification *)aNotification
{
NSFileHandleNotificationDataItem];
if ([data length]) {
/* Process data */
[[aNotification object] readInBackgroundAndNotify];
}
}
- (void)taskEnded:(NSNotification *)aNotification
{
// Task is full complete
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
Post by Colin Swelin
NSPipe *pipes = [NSPipe pipe];
NSTask* patchInstall = [[NSTask alloc] init];
[patchInstall
[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 Swelin
Hi,
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
_______________________________________________
MacOSX-dev mailing list
http://www.omnigroup.com/mailman/listinfo/macosx-dev
--
View this message in context: http://old.nabble.com/Using-NSTask-to-execute-softwareupdate-tp30606801p32479857.html
Sent from the OmniGroup - MacOSX-Dev mailing list archive at Nabble.com.
Colin Swelin
2011-09-16 18:22:20 UTC
Permalink
Hi Charles,

Unfortunately I have not come across a solution to the problem as of yet.

Colin.
Post by Tom Jones
Hi Colin,
I'm having the same issue and I have been unsuccessful in fixing it. Did you
ever resolve this?
Thanks,
Charles
Post by Colin Swelin
Hi,
Sorry for the long reply. I gave this a try and it looked promising,
however, the task still hangs at the "writing files" step of few patches.
It's reading the buffer correctly, as its output everything up to that
point.
Anyone have any insight to why the 10.6.6 update does this?
Thanks again,
Colin
Post by Tom Jones
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];
NSPipe *install_pipe = [NSPipe pipe];
[task setStandardOutput: install_pipe];
[task setStandardError: install_pipe];
NSFileHandle *file = [install_pipe fileHandleForReading];
[[NSNotificationCenter defaultCenter] addObserver: self
name: NSTaskDidTerminateNotification
object: file];
[[NSNotificationCenter defaultCenter] addObserver: self
name: NSFileHandleDataAvailableNotification
object: file];
[file readInBackgroundAndNotify];
[task launch];
[task release];
}
- (void)readFromTask:(NSNotification *)aNotification
{
NSFileHandleNotificationDataItem];
if ([data length]) {
/* Process data */
[[aNotification object] readInBackgroundAndNotify];
}
}
- (void)taskEnded:(NSNotification *)aNotification
{
// Task is full complete
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
Post by Colin Swelin
NSPipe *pipes = [NSPipe pipe];
NSTask* patchInstall = [[NSTask alloc] init];
[patchInstall
[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 Swelin
Hi,
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
_______________________________________________
MacOSX-dev mailing list
http://www.omnigroup.com/mailman/listinfo/macosx-dev
--
View this message in context: http://old.nabble.com/Using-NSTask-to-execute-softwareupdate-tp30606801p32479857.html
Sent from the OmniGroup - MacOSX-Dev mailing list archive at Nabble.com.
_______________________________________________
MacOSX-dev mailing list
http://www.omnigroup.com/mailman/listinfo/macosx-dev
Joar Wingfors
2011-01-08 18:06:05 UTC
Permalink
Post by Colin Swelin
So i'm waiting for the task to complete, then I do my thing with the
results.
One of the most common mistakes with using NSTask is not emptying the pipes as data come in while the task is running. NSPipe has a buffer that can fill up with incoming data, and when it does, the communication stalls until you empty it. See the many discussions on this topic in various Cocoa mailing list archives.

j o a r
Loading...