How do you create the NSFileHandle ?
I succeeded only creating it as
NSFileHandle    *theFileH = [NSFileHandle
     fileHandleForWritingAtPath:tempFilePath];
and the file tempFilePath must exists.

But as I said, I would like to get rid of the temp file.

--
Leo



> Da: Dave DeLong <davedel...@me.com>
> Data: Sat, 27 Nov 2010 08:48:34 -0800
> A: Ben Haller <bhcocoa...@sticksoftware.com>
> Cc: "gMail.com" <mac.iphone....@gmail.com>, Cocoa List
> <cocoa-dev@lists.apple.com>
> Oggetto: Re: NSTask with unzip
> 
> The way I get around this is to use an NSFileHandle for standard out instead
> of an NSPipe. It's a bit less efficient, but slightly more convenient.
> 
> Dave
> 
> Sent from my iPhone
> 
> On Nov 27, 2010, at 7:59 AM, Ben Haller <bhcocoa...@sticksoftware.com> wrote:
> 
>> On 2010-11-26, at 7:33 AM, gMail.com wrote:
>> 
>>> Hi, I can properly unzip a zip file launching a NSTask with /usr/bin/unzip
>>> The task saves the unzipped file to the disk, then a I read the unzipped
>>> file in a NSData. Well. My question is:
>>> Can I do the same job without saving the unzipped file to the disk?
>>> 
>>> I have tried to set the standard output to a pipe - which works well with
>>> other tasks - but here it doesn't work. The task never exits. Here's the
>>> wrong code:
>>> 
>>> NSTask *unzip = [[[NSTask alloc] init] autorelease];
>>> [unzip setLaunchPath:@"/usr/bin/unzip"];
>>> [unzip setArguments:[NSArray arrayWithObjects:@"-p", zipfile,
>>> @"filetounzip", nil]];
>>> 
>>> NSPipe *aPipe = [NSPipe pipe];
>>> [unzip setStandardOutput:aPipe];
>>> [unzip launch];
>>> [unzip waitUntilExit];
>>> 
>>> if([unzip terminationStatus] == noErr){
>>>    dictData = [NSMutableData data];
>>>    while((dataOut = [aPipe availableData]) && [dataOut length]){
>>>        [dictData appendData:dataOut];
>>>    }
>>> }
>> 
>>  If I recall correctly, the problem is likely to be your use of
>> -waitUntilExit.  That API should apparently have a large red label on it
>> ("Warnin', lark's vomit!") since everybody wants to use it this way.  The
>> problem is that the task's output pipe fills up because it isn't being
>> serviced, and then things get locked up.  You need to go with asynchronous
>> reads to service the pipe as output gets stuffed into it.  There should be
>> lots of examples of this on this list, now that you know what to look for.
>> 
>>  What would be great would be a new call, along the lines of
>> -dataFromWaitingUntilExit or some such, that does all this for you, since
>> this is so commonly what people want to do.
>> 
>> Ben Haller
>> McGill University
>> 
>> _______________________________________________
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> 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:
>> http://lists.apple.com/mailman/options/cocoa-dev/davedelong%40me.com
>> 
>> This email sent to davedel...@me.com


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to