views:

356

answers:

2

I have a C library that I'm planning to use in an iPhone application. It writes a lot of its debug information to stderr. Is there an easy way to redirect stderr/stdout to my XCode console?

Will I have to write wrappers that call NSLog? If so, what would be the best way of doing so?

+3  A: 

I know that stdout at least already goes to the console. I am not 100% sure about stderr.

You can simply do a print, and it will end up in XCode's console.

Edit: Found some references confirming stderr as well.

Jeff B
Daniel
Do your lines end with "\n"? If not, the buffer may not be written out immediately. There is a long discussion/argument about this here: http://forums.macrumors.com/archive/index.php/t-147797.html%3C/t-511473.html
Jeff B
Jeff B: Heh, forgot to flush. Thanks for that, all working! :)
Daniel
+2  A: 

There’s no need to redirect anything, all the output goes to the console already. Try that:

fprintf(stdout, "Standard output.\n");
fprintf(stderr, "Standard error output.\n");
zoul