views:

185

answers:

4

I can do it from XCode, but I want to be able to launch an iPhone App (on the device) from the command line. Is it possible?

Why? Because I want to capture some of the output for semi-automated testing. I'm guessing I need to use a debug build for NSLog output, but I'd also be interested to know about other methods for getting NSLog / stdio data back to the host Mac.

+1  A: 

There is a project on github called titanium_mobile (part of Titanium Developer).

I use a utility from that project called iphonesim. It launches an iPhone app from the command line (though I am not sure how, I think there is a way to do that with SpringBoard.app). If you take a step up one level in the Titanium Mobile code and look at builder.py you can see how they launch an app in the simulator and capture the output.

Jackson Miller
That's a very interesting piece of code to mine, thanks. I could almost get it working on the simulator - certainly learnt a lot about building a launching iPhone apps automatically. In the end I found a different solution to my specific need, but I think the technique is of interest in general.
atobe
The original iphonesim project is here: http://github.com/jhaynie/iphonesim
apenwarr
A: 

You can do this on the device if it is jailbroken. You can put a debug build and symbols on your device and run gdb on it. It is totally unsupported but I hear it works. Not sure if there is a good tutorial. Google?

St3fan
+1  A: 

One method would be to use the AsyncSocket class, and pass whatever data you want to log from the iPhone to a basic host app on the Mac, which NSLogs whatever it receives. If you follow the EchoServer application, you should be able to integrate it in just a few minutes

SpenserJ
This sounds like a good way forward. In the end I found a different solution to my specific need, but I think this would work.
atobe
+1  A: 

Ultimately I solved my specific need a different way. I needed to get data from the iPhone's accelerometers into a prototype app in Adobe AIR(Flash).

I used this app on the iPhone which drops UDP packets with X,Y,Z forces in them. http://code.google.com/p/accelerometer-simulator/wiki/Home

Found that from this blog post which might be of interest to people trying to do other similar things. http://ifiddling.blogspot.com/2009/01/dummy2.html

I used a Python script to present a server to Flash, grab UDP accelerometer packets, munge them into AMF and send them to Flash. Flash uses a socket to connect to this server and receive the accelerometer data.

A few parts, but it works nicely.

atobe