I'm trying to redirect stdout using the accepted answer in here but the notification doesn't seem to be called.
I'm not interested in NSLog
outputs, but in the system outputs to the console.
Don't know if it is the right method to do it, but I couldn't find any other working example of achieving this,
And this one (even tough currently not working) seems to be the simplest out of all the results I've found (most were using a lot of C syntax I'm not familiar with).
I'm developing an app for my personal use so don't care about App Store.
Target iOS is 7.1.2 and I'm using Xcode 5, if it is matter in any way.
Currently I'm testing it on iOS 7.1 simulator.
Here is the code I was trying:
// In view did load
NSPipe *pipe = [NSPipe pipe] ;
pipeReadHandle = [pipe fileHandleForReading] ;
dup2([[pipe fileHandleForWriting] fileDescriptor], fileno(stdout)) ;
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(handleNotification:) name: NSFileHandleReadCompletionNotification object: pipeReadHandle] ;
[pipeReadHandle readInBackgroundAndNotify] ;
I've also implemented the handleNotification:
method, but I've not included it here because it is irrelevant, since it is not getting called at all....
The code above is used for OS X, do I need modify something for iOS usage?
Any ideas why it isn't working, or suggestions on better approach to achieve it?