1

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?

Community
  • 1
  • 1
AMI289
  • 1,098
  • 9
  • 10
  • 1
    You seem to be assuming that the "console" output is `stdout`. I'm positive but I don't believe that is a valid assumption in iOS. – rmaddy Jan 13 '15 at 17:54
  • Try looking at `asl` and also `NSLogv` docs, you might find what you need. – CRD Jan 13 '15 at 18:42
  • @rmaddy you are right mate, I was assuming that console is just a 'view' of stdout, but from your comment I understand it isn't so, can I use CRD's suggestion to 'capture' the console output? – AMI289 Jan 13 '15 at 19:56
  • @CRD thanks, I'll have a look into those. – AMI289 Jan 13 '15 at 20:00
  • @AMI289 I just noticed a typo on my first comment. I meant to say "I'm not positive but ..." – rmaddy Jan 13 '15 at 20:11

0 Answers0