NSPipe
NSPipe
- Subject: NSPipe
- From: Martin Ekerå <email@hidden>
- Date: Mon, 16 Jul 2001 15:35:28 +0200
Hello,
I've attempted to use the following piece of code to pipe data
between two NSTask processes (cat and tail).
--- cut (piper.m) ---
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSTask *task = [[NSTask alloc] init];
NSPipe *pipe;
pipe = [NSPipe pipe];
task = [[NSTask alloc] init];
[task setCurrentDirectoryPath:@"/bin"];
[task setLaunchPath:@"/bin/cat"];
[task setStandardOutput:pipe]; // write to pipe
[task setArguments:[@"smdb.db" componentsSeparatedByString:@" "]];
[task launch];
[task waitUntilExit];
task = [[NSTask alloc] init];
[task setCurrentDirectoryPath:@"/usr/bin"];
[task setLaunchPath:@"/usr/bin/tail"];
[task setStandardInput:pipe]; // read from pipe
[task setArguments:[@"-n 2" componentsSeparatedByString:@" "]];
[task launch];
[task waitUntilExit];
[pool release];
return 0;
}
--- cut (piper.m) ---
When the file "smdb.db" is below 8 kb in size, this method works
perfectly. When it is larger than 8 kb however (8 192 bytes) the
application stalls and does not output anything. I waited for over 5
minutes but I still didn't get any result...
If I redirect stndOut of cat to a file using an NSFileHandle, and
then pass the location of that file to tail (that is; if I do not use
NSPipe:s) I can use files well over 35 mb ( 2,67 million lines).
Is there a limitation for how much data you can send through an
NSPipe? Or am I not using the NSPipe correctly? Please help me out
here; I've looked all over developer.apple.com, TIL and
connect.apple.com but I can't find any report of a bug in the NSPipe
definition...(?)
Thank you in advance,
Martin Ekere
email@hidden