• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTask and piped commands
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >NSTask and piped commands (From: appledev <email@hidden>)
 >Re: NSTask and piped commands (From: Alastair Houghton <email@hidden>)

  • Prev by Date: Re: NSTask and piped commands
  • Next by Date: Re: NSTask and piped commands
  • Previous by thread: Re: NSTask and piped commands
  • Next by thread: Re: NSTask and piped commands
  • Index(es):
    • Date
    • Thread