I am trying to create a simple tool that can create, write and read a named pipe. Here is the code.
int main(int argc, const char * argv[])
{
@autoreleasepool
{
//create pipe
system("rm /tmp/myPipe");
system("mkfifo /tmp/myPipe");
system("chmod 666 /tmp/myPipe");
// write to pipe
NSString *text = [NSString stringWithFormat:@"this is a test"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:@"/tmp/myPipe" isDirectory:NO])
{
NSFileHandle *fileHandle=[NSFileHandle fileHandleForWritingAtPath:@"/tmp/myPipe"];
[fileHandle seekToEndOfFile];
[fileHandle writeData:[text dataUsingEncoding:NSUTF8StringEncoding]];
[fileHandle closeFile];
}
}
return 0;
}
The file is created correctly with perms of prw-rw-rw- 1 xxx wheel 0 May 17 09:48 myPipe|
When I run the tool it hangs at the line:
NSFileHandle *fileHandle=[NSFileHandle fileHandleForWritingAtPath:@"/tmp/myPipe"];
What am I missing here?