Re: Using NSTask to execute softwareupdate
Colin Swelin <[email protected]> Fri, 16 Sep 2011 14:22:20 -0400
| Newsgroups | gmane.comp.macosx.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Charles,
Unfortunately I have not come across a solution to the problem as of =
yet.
Colin.
On 2011-09-16, at 11:29 AM, sunfire wrote:
>=20
> Hi Colin,
> I'm having the same issue and I have been unsuccessful in fixing it. =
Did you
> ever resolve this?
>=20
> Thanks,
> Charles
>=20
>=20
> Colin Swelin wrote:
>>=20
>> Hi,
>>=20
>> 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.
>>=20
>> Anyone have any insight to why the 10.6.6 update does this?
>>=20
>> Thanks again,
>> Colin
>>=20
>> On 2011-01-08, at 1:27 PM, Tom Jones wrote:
>>=20
>>> The problem is the use of "waitUntilExit" the buffer is filling up.=20=
>>>=20
>>> Try something like this...
>>> ( You might have to clean some of it up :-) )
>>>=20
>>> Tom
>>>=20
>>> - (void)runTask:(NSDictionary *)patch
>>> {
>>> NSTask *task =3D [[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"]];
>>>=20
>>> NSPipe *install_pipe =3D [NSPipe pipe];
>>> [task setStandardOutput: install_pipe];
>>> [task setStandardError: install_pipe];
>>> =09
>>> NSFileHandle *file =3D [install_pipe fileHandleForReading];
>>>=20
>>>=20
>>> [[NSNotificationCenter defaultCenter] addObserver: self
>>> =
selector: @selector(taskEnded:)
>>> =
name: NSTaskDidTerminateNotification
>>> =
object: file];
>>>=20
>>> [[NSNotificationCenter defaultCenter] addObserver: self
>>> =
selector: @selector(readFromTask:)
>>> =
name: NSFileHandleDataAvailableNotification
>>> =
object: file];
>>>=20
>>> [file readInBackgroundAndNotify];
>>> [task launch];
>>> [task release];
>>> }
>>>=20
>>>=20
>>> - (void)readFromTask:(NSNotification *)aNotification
>>> {
>>> NSData *data =3D [[aNotification userInfo] objectForKey:
>>> NSFileHandleNotificationDataItem];
>>> if ([data length]) {
>>> /* Process data */
>>> [[aNotification object] readInBackgroundAndNotify];
>>> }
>>> }
>>>=20
>>> - (void)taskEnded:(NSNotification *)aNotification
>>> {
>>> // Task is full complete
>>> [[NSNotificationCenter defaultCenter] removeObserver:self];
>>> }
>>>=20
>>>=20
>>>=20
>>> On Jan 8, 2011, at 9:59 AM, Colin Swelin wrote:
>>>=20
>>>> Here's the basic NSTask stuff:
>>>>=20
>>>>=20
>>>> NSPipe *pipes =3D [NSPipe pipe];
>>>> NSTask* patchInstall =3D [[NSTask alloc] init];
>>>> [patchInstall
>>>> setLaunchPath:@"/usr/sbin/softwareupdate"];
>>>> [patchInstall setArguments:[NSArray =
arrayWithObjects:@"-i", [patch
>>>> objectForKey:@"patch_identifier"], nil]];
>>>> =09
>>>> [patchInstall setStandardOutput: pipes];
>>>>=20
>>>> NSFileHandle *file =3D [pipes
>>>> fileHandleForReading];
>>>> =09
>>>> [patchInstall launch];
>>>> =09
>>>> NSData *data =3D [file readDataToEndOfFile];
>>>> =09
>>>> [patchInstall waitUntilExit];
>>>>=20
>>>>=20
>>>> ......
>>>> [patchInstall release];
>>>>=20
>>>>=20
>>>> So i'm waiting for the task to complete, then I do my thing with =
the
>>>> results.=20
>>>>=20
>>>> Thanks,
>>>> Colin
>>>>=20
>>>> On Sat, Jan 8, 2011 at 12:48 PM, Tom Jones <[email protected]> =
wrote:
>>>> 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?
>>>>=20
>>>>=20
>>>> Thanks,
>>>> tom
>>>>=20
>>>>=20
>>>> On Jan 6, 2011, at 8:54 AM, Colin Swelin wrote:
>>>>=20
>>>>> Hi,
>>>>>=20
>>>>> 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.
>>>>>=20
>>>>> 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.
>>>>>=20
>>>>> Thanks._______________________________________________
>>>>> MacOSX-dev mailing list
>>>>> [email protected]
>>>>> http://www.omnigroup.com/mailman/listinfo/macosx-dev
>>>>=20
>>>>=20
>>>=20
>>=20
>> _______________________________________________
>> MacOSX-dev mailing list
>> [email protected]
>> http://www.omnigroup.com/mailman/listinfo/macosx-dev
>>=20
>>=20
>=20
> --=20
> View this message in context: =
http://old.nabble.com/Using-NSTask-to-execute-softwareupdate-tp30606801p32=
479857.html
> Sent from the OmniGroup - MacOSX-Dev mailing list archive at =
Nabble.com.
>=20
> _______________________________________________
> MacOSX-dev mailing list
> [email protected]
> http://www.omnigroup.com/mailman/listinfo/macosx-dev