没有调试器,Stdout重定向在iOS中不起作用

编程入门 行业动态 更新时间:2024-10-26 16:31:16
本文介绍了没有调试器,Stdout重定向在iOS中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试重定向输出,以便可以通过网络发送它.由于某种原因,如果您在调试器附加时运行代码,则它可以完美运行.以正常方式启动应用程序后,代码将冻结在读取函数上,并且永远不会返回.如果有人有任何指点,我将不胜感激.

I am trying to redirect output so I can send it over the network. For some reason if you run the code while debugger attached it works perfectly. Once you start the application in normal way the code freezes on the read function and never returns. If someone has any pointers I will highly appreciate it.

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^(void) { static int pipePair[2]; if ( pipe(pipePair) != 0) { return; } dup2(pipePair[1],STDOUT_FILENO); while (true) { char * buffer = calloc(sizeof(char), 1024); ssize_t readCount = read(pipePair[0],buffer,1023); if (readCount > 0) { buffer[readCount] = 0; NSString * log = [NSString stringWithCString:buffer encoding:NSUTF8StringEncoding]; //sent it over network } if (readCount == -1) { return; } } });

推荐答案

显然,在iOS 5.1中,不允许向stdout写入数据. spouliot.wordpress/2012/03/13/ios-5-1-vs-stdout/

Apparently in iOS 5.1 writing to stdout was disallowed. spouliot.wordpress/2012/03/13/ios-5-1-vs-stdout/

更多推荐

没有调试器,Stdout重定向在iOS中不起作用

本文发布于:2023-10-09 10:34:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1475501.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中不   重定向   调试器   Stdout   iOS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!