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: