I’m looking for a way to redirect/capture the stdout output of a native library in a simple Android app. I’ve seen a couple posts on this but I’m not finding the answers to my questions.
As much as possible I’d like to avoid tinkering with the existing native library. My first impulse is to use a fifo file and redirect the native library’s output. I can’t seem to get past the call to Runtime.getRuntime().exec(“mkfifo(,0666)”). I’m trying to create the file in /data/data/ but the file doesn’t seem to exist after the program runs. I also can’t seem to find ‘mkfifo’ in the Android filesystem (via adb shell).
Couple of dumb questions:
– Where is mkfifo?
– Should I be able to see the fifo file after the program runs or is there a more reliable way to test the fifo’s existence from Java after I run the above command?
– Is there another/better approach to take for this?
Thanks.
Do you want to redirect it specifically to a file? Then what you probably wanna do is:
I have no idea how will this affect the Java subsystem.
Also note that the
/data/datamight not be writable. The application sandbox is under/data/data/com.mypackage/, and Android expects you to create subdirectories for your data there viaContext.getDir()./sdcardis always writable, but you have to check availability first – the card is by definition removable storage.If redirecting to a file is not your ultimate desire, then
pipe()might be a better choice.dup2()the write end to 1, and read from the read end, preferably in a different thread. Then it’s up to you what to do to the data read.