1
명명 된 파이프를 만들고, 쓰고 읽을 수있는 간단한 도구를 만들려고합니다. 여기에 코드가 있습니다. |명명 된 파이프에 읽기 및 쓰기 사용
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;
}
파일은 PRW-RW-rw-을 1 개 XXX 휠의 파마 17 9시 48분 myPipe 0 월 제대로 작성
나는 줄에서이 중단 도구를 실행하면 :
NSFileHandle *fileHandle=[NSFileHandle fileHandleForWritingAtPath:@"/tmp/myPipe"];
나는 여기에 놓치고 무엇을?
되지는 문제의 원인이 있지만,'-fileExistsAtPath입니다 : isDirectory :'소요 'BOOL *'인수를 두 번째 인수로 사용하십시오. 'NULL'을 전달하는 것과 동일한'NO'를 전달 했으므로 코드는 그 행에서 충돌하지 않습니다. – bbum
분명히 fifo와 파이프를 섞을 수는 없습니다. 더 많은 정보는 여기 : https://forums.developer.apple.com/thread/74001 – bbum