Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is redirecting stdout/stderr on android not working?

I downloaded SDL 1.3 and tested it together with OpenGL ES on my android 2.2 device. It works fine but I don't get the outputs from the printf calls. I tried the commands below as mentioned at the android developer page but neither DDMS in Eclipse nor adb logcat reports the strings that the program writes using printf. I made sure to filter for the stdout tag.

$ adb shell stop
$ adb shell setprop log.redirect-stdio true
$ adb shell start

What am I missing or doing wrong?

like image 232
trenki Avatar asked Mar 31 '11 11:03

trenki


People also ask

Can stderr be redirected?

The regular output is sent to Standard Out (STDOUT) and the error messages are sent to Standard Error (STDERR). When you redirect console output using the > symbol, you are only redirecting STDOUT. In order to redirect STDERR, you have to specify 2> for the redirection symbol.

How do I redirect stderr and stdout to a file?

The I/O streams can be redirected by putting the n> operator in use, where n is the file descriptor number. For redirecting stdout, we use “1>” and for stderr, “2>” is added as an operator. We have created a file named “sample. txt” to store the redirected output in our current directory.


1 Answers

According to this presentation, log.redirect-stdio is for Dalvik output, to redirect C/C++ output (such as printf), you must install busybox on the device and use its xargs utility like this:

myprogram | xargs log

This obviously works for code that gets called as a standalone executable. If it's only for debugging purposes, you can write a tiny program to call your library and call that from your application using xargs.

like image 97
gfour Avatar answered Oct 06 '22 14:10

gfour