Re: NSTask and piped commands
Re: NSTask and piped commands
- Subject: Re: NSTask and piped commands
- From: René v Amerongen <email@hidden>
- Date: Wed, 19 May 2010 00:05:48 +0200
Thanks for this.
Your right about this idea. I will check it out.
René
Op 18 mei 2010, om 22:34 heeft Alastair Houghton het volgende geschreven:
> On 18 May 2010, at 20:33, appledev wrote:
>
>> [task launch];
>>
>> [task waitUntilExit];
>>
>> NSData *data;
>> result = [file readDataToEndOfFile];
>
> This part is not safe. If the tasks output enough data to fill the pipe buffer (which may be of whatever size the kernel chooses to make it), then your program will hang on the -waitUntilExit line.
>
> You should instead do something like
>
> NSMutableData *result = [NSMutableData data];
> NSData *chunk;
>
> while ((chunk = [file availableData]) && [chunk length])
> [result appendData:chunk];
>
> [task waitUntilExit];
>
> There are obviously variations on that; if you can process the data as you go, that may be a better way to do it (but it's a bit complicated to do because there's no guarantee that the chunks you read won't straddle individual multi-byte characters).
>
> Kind regards,
>
> Alastair.
>
> --
> http://alastairs-place.net
>
>
>
>
_______________________________________________
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