문제

I've created a file by using mkfifo /tmp/my.fifo. I now want to write chars into the file (with Objective C) to be able to grab them by tail -f /tmp/my.fifo. For some reason this does not work. The tail command only displays one character, and then stops output.

Objective C Code:

NSError *error = nil;

[buffer writeToFile:@"/tmp/my.fifo" atomically:YES encoding:NSUTF8StringEncoding error:&error];
if(error){
    NSLog(@"Fail: %@",[error localizedDescription]);
}

The NSLog does not output anything. So from Objective C perspective theres obviously no error.

도움이 되었습니까?

해결책

Solution was simpler than I thought:

NSFileHandle *fileHandle=[NSFileHandle fileHandleForWritingAtPath:@"/tmp/my.fifo"];
[fileHandle seekToEndOfFile];
[fileHandle writeData:[buffer dataUsingEncoding:NSUTF8StringEncoding]];
[fileHandle closeFile];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top