Source code is toolio. cpp in the flying project (http://code.google.com/p/flying-on-android/)
This program mainly demonstrates how to redirect stdout and stderr of a program.
Processes started by the system in Android, stdout and stderr are directed to/dev/null by default. Therefore, the output of the program is invisible from the ADB shell, you can only print data by using logw and other methods, and then view data by using logcat.
However, executable binary programs started from shell are not redirected, and stdout and stderr are directed to the terminal at startup. You can compile and run toolio:
Toolio
Use the default stdout and stderr. All outputs are displayed.
Toolio Console
Redirects stdout and stderr to/dev/console. The output results are the same as those before redirection.
Toolio null
Redirects stdout and stderr to/dev/null. No output is visible after redirection.
This indicates that when toolio is started from the shell through the serial port, the stdout and stderr of the program are both/dev/console like toolio. Therefore, when redirected to/dev/console, the output remains unchanged.
There are many printf In the android source code, but these outputs are not visible in the serial port, because the program compiled by the source code is not started through the serial port.
In addition, stderr in Bionic of Android is not buffered by default, while stdout is buffered. If there is a buffer, the characters written to stdout will be accumulated until the buffer is full or/N is met, all the content will be printed once.