嗨:我想将stdout重定向到NSTextView.这也适用于子流程的输出吗?什么是实现这一目标的最佳方法?
编辑: 根据Peter Hosey的回答我实施了以下内容.但我没有得到通知.我究竟做错了什么?
NSPipe *pipe = [NSPipe pipe];
NSFileHandle *pipeHandle = [pipe fileHandleForWriting];
dup2(STDOUT_FILENO, [pipeHandle fileDescriptor]);
NSFileHandle *fileHandle = [[NSFileHandle alloc] initWithFileDescriptor:pipeHandle];
[fileHandle acceptConnectionInBackgroundAndNotify];
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
[dnc addObserver:self selector:@selector(handleNotification:) name:NSFileHandleConnectionAcceptedNotification object:fileHandle];
Run Code Online (Sandbox Code Playgroud)