Re: NSTask and NSPipe has buffering issues?
Re: NSTask and NSPipe has buffering issues?
- Subject: Re: NSTask and NSPipe has buffering issues?
- From: "Mr. Gecko" <email@hidden>
- Date: Wed, 01 Aug 2012 05:56:07 -0500
Thank you!
That makes lots of sense and I was able to fix my code. I knew that I sometimes got zero length data, but never knew why. Now that I know it's the end of fileā¦ I can make lots of use of this knowledge.
Thanks for the help.
On Jul 31, 2012, at 11:20 PM, Ken Thomases <email@hidden> wrote:
> NSPipe itself doesn't require that a run loop be run, but the "InBackgroundAndNotify" methods of the associated NSFileHandle objects do.
>
> You receive a zero-length NSData when (and only when) a read encounters EOF.
>
> There is an inherent race between the receipt of the task termination notification and getting end-of-file on the output and error pipes. This race is not in Cocoa, it's in the kernel and the interprocess communication mechanisms. You can't rely on having received all of the data by the time you are notified of the task termination.
>
> You should separately track when NSTask has posted the termination notification and when each pipe has gotten EOF. Keep looping around the run loop until *all three* things have happened. (In other words, generalize from your "running" variable. You had the right idea but hadn't covered all of the important parts.)
>
> Regards,
> Ken
>
_______________________________________________
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