Re: NSUnbufferedIO
Re: NSUnbufferedIO
- Subject: Re: NSUnbufferedIO
- From: Don Yacktman <email@hidden>
- Date: Sun, 13 Oct 2002 00:02:30 -0600
On Saturday, October 12, 2002, at 10:24 PM, Jim Balhoff wrote:
Hi all,
I just got the new "Cocoa Programming" book by Anguish et al., and I
found something very useful in the section about NSTask. They mention
that processes launched with NSTask in Project Builder have the
environment variable NSUnbufferedIO set to "YES", while those launched
from Finder use "NO" by default, which can lead to unexpected results.
They then show how to set this value for one's NSTask instance.
My question is, how could I have found out about NSUnbufferedIO without
happening upon it in this book?
I searched the web with Google, Apple's developer site with Google, and
used the batch find in Project Builder, and found no instances of the
word NSUnbufferedIO.
Well, I'll tell you how I found out about it.
I was working on the Animal example, and found that it worked great from
PB, but not when double clicked in Finder. So I figured, "hmmm, I bet
it is something in the runtime environment that's different". So I
dumped out the task's environment variables. There was literally only
one difference: the NSUnbufferedIO flag. So, I added code to set the
flag for the child process, and bingo, it works right from then on. So
I figured it would be a really good idea to mention it in the chapter,
since I don't think I'll be the only one to bump into that issue. ;-)
I should note that this trick only works for Foundation based programs;
a straight C based program might still have buffering problems. In that
case, you have to go to more trouble and use a pty for the I/O. There's
code for how to do that on the net if you hunt around a bit. The
chapter was getting too long, so I didn't go into ptys. I figured
that's more of a topic for a very advanced Cocoa book -- or at least,
beyond what I could cram into this book!
And you're right, NSUnbufferedIO isn't documented anywhere that I am
aware of. In fact, there are a lot of command line flags you can use
when launching Cocoa programs that don't seem to be documented but can
be very handy. I think my graphics chapters mentions some of them. And
there are probably many that I don't even know about. I really wish
Apple would document them all!
--
Later,
Don Yacktman
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.