iOS - NSFileHandle availableData仅在应用程序在设备上手动运行时挂起

时间:2012-09-19 23:06:34

标签: ios stdout nsfilehandle

我设置了一个文件句柄来读取stdout的内容,当我尝试使用av​​ailableData从中提取数据时,它会挂起,但只有在我的设备上手动运行应用程序时才会挂起。当我通过Xcode或模拟器在我的设备上运行应用程序时,它会按预期将数据拉出,其余代码完美运行。有什么想法发生了什么?我的代码如下:

int pipefd[2];                
pipe(pipefd);
dup2(pipefd[1], STDOUT_FILENO);
close(pipefd[1]);

NSFileHandle *stdoutReader = [[NSFileHandle alloc] initWithFileDescriptor:pipefd[0]];

// this method writes output to stout
int result = [self createOutput:string1:string2];

// code hangs on this next line when app is run manually on device)
NSData *stdoutData = [stdoutReader availableData];

我想知道如果在我的设备上,createOutput方法运行得更慢,那么当我尝试从stdout中获取数据时,还没有呢?

1 个答案:

答案 0 :(得分:1)

好吧,看起来iOS 5.1不再允许写入stdout了。对于有兴趣阅读更多内容的人来说,这是一篇内容丰富的博文:http://spouliot.wordpress.com/2012/03/13/ios-5-1-vs-stdout/