Re: NSTask and NSPipe has buffering issues?
Re: NSTask and NSPipe has buffering issues?
- Subject: Re: NSTask and NSPipe has buffering issues?
- From: Ken Thomases <email@hidden>
- Date: Wed, 01 Aug 2012 00:20:29 -0400
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