views:

705

answers:

1

I don't like using Xcode's console output window when debugging an iPhone app in the Simulator (or on a device for that matter). I'd like to be able to use the Unix toolbox and do things like filter the logging output with grep. But to do this I need to get Xcode to send the logging output for the running iPhone app to the Terminal.

Is there any way to accomplish this?

+1  A: 

Couldn't say how it'd work in the simulator, but redirecting stdout is not terribly difficult. Say you wanted to pipe it into your own view:

#include <unistd.h>

stderr->_write = RedirectOutputToView;
stdout->_write = RedirectOutputToView;

And use the prototype:

int RedirectOutputToView(void *inFD, const char *buffer, int size);
Azeem.Butt
I know how to redirect stdout. I just need to know how to get an iPhone app running in debug mode in XCode to output to stdout of the Terminal.
dan
Thanks, but there must be a simpler way to do this. For example, if there was a way (which I don't know about) to launch the iPhone app in the iPhoneSimulator directly from the Terminal, then presumably the logging output would appear in the Terminal window you launched the app from.
dan
So redirect it to a file and run tail -f on that. If Terminal has a stdout, you don't get to write to it from outside its address space.
Azeem.Butt
If XCode wrote its console log output to a file somewhere, it would be great to know so we could tail -f that directly.
dan
Aha, I got it working. The solution was something like NSString *logPath = @"/path/to/log/file.log";freopen([logPath fileSystemRepresentation], "a", stderr);in the main() function
dan