有什么方法从stdin在iPhone上阅读,硬件或模拟器? [英] Is there any way of reading from stdin on iPhone, either hardware or emulator?

查看:253
本文介绍了有什么方法从stdin在iPhone上阅读,硬件或模拟器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从XCode调试OSX应用程序时,我可以从XCode调试控制台与应用程序的控制台通信 - 例如,应用程序可以 printf() stdout 并显示在XCode调试控制台上,我的应用程序可以在 stdin上调用 fgets()



看起来像XCode,当调试iOS iPhone应用程序时,它挂接 stdout printf()等工作正常),但不是 stdin



有人在iOS / iPhone上做过 stdin 这在调试期间非常有用 - 即使使用iOS Cocoa应用程序。我可以让这个工作在一些更复杂的方式,像一个套接字,但我只是希望XCode为我做这个。



更新:



好吧,这会解释一下。 iOS模拟器实际上为 stdin 打开 / dev / null 。可以找出 stdout 正在进行的位置(通常为 / dev / ttys00X ),然后使用<$ c重新打开$ c> O_RDONLY 并将其分配给stdin。这对iOS模拟器很有用,但它看起来像串行连接到iphone硬件的线规则是错误的 - 你可以在xcode调试控制台中输入输入,并且它永远不会发送到iphone硬件(和你的程序运行在iPhone硬件上只会坐等待某事出现在 stdin aka / dev / ttys00X )。

解决方案

我想知道有没有办法让这个工作与iPhone硬件?

我没有解决这个确切的问题,很可能没有办法这样做。我有一个替代建议。我在我的一个项目中使用它,它工作相当不错。



我使用 AsyncSocket 库实现一个微TCP服务器,我可以连接到使用telnet和我的应用程序通信。此方法有几个优点:




  • 您不必在调试器下运行


  • 可以通过任何计算机访问该应用程序

  • 可以访问该应用程序可批处理多个命令)

  • 可扩展(易于使HTTP服务器与浏览器连接)


When I debug an OSX application from XCode, I can communicate with the application's console from the XCode debugging console - for example, the application can printf() to stdout and that's displayed on the XCode debugging console, and my application can call fgets() on stdin to which I can type input in the XCode debug console.

It seems like XCode, when debugging iOS iPhone applications, hooks up stdout (printf() et. al. work fine), but not stdin?

Has anyone made stdin on iOS/iPhone work? This would be just tremendously useful during debugging - even with an iOS Cocoa app. I could get this to work in some more complicated way, like with a socket, but I'd just rather have XCode do this for me.

UPDATE:

Well, this would explain it. The iOS simulator actually opens /dev/null for stdin. It's possible to find out where stdout is going (typically /dev/ttys00X) and then reopen that with O_RDONLY and assign it to stdin. This works great for the iOS simulator, but it looks like the line discipline for the serial connection to the iphone hardware is wrong - you can keep typing input in the xcode debug console and it never gets sent to the iphone hardware (and your program running on the iPhone hardware will just sit waiting for something to show up on stdin aka /dev/ttys00X).

I wonder if there's any way to get this working with the iPhone hardware?

解决方案

I don't have a solution to this exact problem and it's quite possible that there's no way to do that. I have an alternative suggestion. I used it in one of my projects and it worked quite well.

I used the AsyncSocket library to implement a micro TCP server, which I could connect to using telnet and communicate with my app. There's a few advantages to this approach:

  • you don't have to run under the debugger
  • the app is accessible from any computer
  • it's possible to access the app on somebody else's phone (handy when in a team)
  • it's scriptable (can batch multiple commands)
  • extendable (easy to make an HTTP server out of this to connect with a browser)

这篇关于有什么方法从stdin在iPhone上阅读,硬件或模拟器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆