NSTask/NSPipe STDIN hangs on large data, sometimes...
NSTask/NSPipe STDIN hangs on large data, sometimes...
- Subject: NSTask/NSPipe STDIN hangs on large data, sometimes...
- From: "Joe Pezzillo" <email@hidden>
- Date: Thu, 16 Jan 2003 15:25:16 -0700
Greetings!
This being my first post to the list, permit me the obligatory passing
mention that I've been having a blast with Cocoa and am very impressed with
how quickly I've been able to build useful applications. I'd used PowerPlant
in the past, but the combination of the supplied Frameworks with Objective-C
is, IMHO, much, much better (read: easier to use!)...not to mention that
awesome OS under the hood.
Of course, I wouldn't be posting if I didn't have an issue.
After months of learning on my own (many thanks to the great books that are
out there) and trial-and-error with the classes, I'm finally completely
stumped.
I have fully functioning implementations of synchronous and asynch
NSTasks/NSPipes to execute UNIX command line programs, passing and
retrieving data via STDIO. [Many thanks to the Moriarty sample code, the G&M
O'Reilly Book, and A/B/Y's Sams book!!!]
Mostly, this works just fine.
HOWEVER, some commands (or the pipe that's feeding them their STDIN) seem to
choke if I'm sending a large amount of data into the command via STDIN.
For example, on the terminal command line, I can do this:
% cat /var/log/httpd/access_log | grep Jan
And even though the access_log is > 1MB, it works fine, as expected.
HOWEVER, if I try the same thing using NSTask/NSPipe in Cocoa, it hangs
during writeData: to the STDIN file handle, but only if there is a lot of
data being sent to grep.
I have done some research on the problem (in part to be sure this is really
a problem before posting to the list), and I can tell you that some commands
(eg, tail, sort, wc) work great, even with large stdin writes (those three
in particular were tested up to 8MB, and they worked fine!).
In particular, grep (and/or egrep) starts to hang if the STDIN is 40K or
larger and uniq hangs at about 32K. And I mean hang, the app doesn't die or
exit, it just hangs during writeData: to the Task's stdIn pipe's file handle
for writing. The exact same code is used for all the tests described above.
I have tried changing the NSUnbufferedIO environment setting, no help.
What else can I try? What am I missing?
Has anyone else experienced this problem and solved it or am I a lone corner
case? I googled a little and have looked at some of the Cocoa sites (and
this list), but nothing jumped out at me that was addressing or solving this
issue.
Is this a problem with my code (I'll post a spike of the app if needed) or
the frameworks or Darwin, OR?
I'm running 10.1.5 (uname -a below) on a PBG4/550Mhz/GBEther. I have a
non-development Jaguar box I could test this on (actually, it's a
half-sphere, not a box at all!), but it's burning a DVD for the next hour or
two, so I don't really want to muck with it at the moment to test this.
Especially since I want this to work even on 10.1.5 and hopefully since
someone out there has already solved this.
Thanks for your help, and thanks for Cocoa!
Joe Pezzillo
Boulder, CO | Santa Cruz, CA
<email@hidden>
% uname -a
Darwin silvern 5.5 Darwin Kernel Version 5.5: Thu May 30 14:51:26 PDT 2002;
root:xnu/xnu-201.42.3.obj~1/RELEASE_PPC Power Macintosh powerpc
_______________________________________________
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.