4

How can I get the cout output of the native c++ program on the log-cat in android application development in eclipse.

Please someone help me here.

Fayaz Ali
  • 61
  • 1
  • 6

1 Answers1

5

The stdout/stderr file descriptors are sent to /dev/null in Android apps. (The Java equivalents, System.out and System.err, are redirected to the log by the app framework.)

The Dalvik VM includes a hack that will let you see stdout/stderr on a rooted device by setting the log.redirect-stdio property. See this link for details. It works by starting a thread that reads from the stdio file descriptors and copies the data to the logging system.

For new code, it's much easier to use the Android log calls directly. If you're importing a library from elsewhere, of course, it's a bit harder. If necessary you could copy the code out of Dalvik and into your app and have it do the same thing.

fadden
  • 51,356
  • 5
  • 116
  • 166
  • Thanks for this - that's apparently what happens- but why the docs say : "By default, the Android system sends stdout and stderr _(System.out and System.err)_ output to /dev/null." (emphasis mine). See : http://developer.android.com/tools/debugging/debugging-log.html#viewingStd – Mr_and_Mrs_D Nov 20 '13 at 01:16
  • 1
    The docs are wrong. I filed https://code.google.com/p/android/issues/detail?id=62555 . – fadden Nov 20 '13 at 17:49
  • Thanks a lot ! +1 - I can't stand uncertainty :) – Mr_and_Mrs_D Nov 20 '13 at 18:56
  • interesting fadden :) – Whoami Mar 10 '14 at 12:23