TLDR; Problem:
When I run my native Android executable alone with Runtime.exec(), I can get its printf() outputs from my app. But when I do it with Runtime.exec("su -c <native executable>"), I can't get its outputs anymore.
Better explanation:
So, say I have an Android app that has a native executable called "executable". I rename "executable" to "libexecutable.so" to trick the apk installer into copying the file over into the device.
Then, the app runs the executable with
String executable = context.getFilesDir().getParent() + "/lib/libexecutable.so";
String me = context.getPackageName();
Process p = Runtime.getRuntime().exec(String.format("%s %s", executable, me));
From my native executable, whenever I use printf(), I can get the output in my app with p.getInputStream(). Perfect.
However, this native executable needs root permissions, so, I run it like this:
String su = "su -c";
String executable = context.getFilesDir().getParent() + "/lib/libexecutable.so";
String me = context.getPackageName();
Process p = Runtime.getRuntime().exec(String.format("%s %s %s", su, executable, me));
Now, whenever my native executable uses printf(), I no longer can get the output with p.getInputStream().
I looked it up and got to this: Java: can't get stdout data from Process unless its manually flushed
And tried fflush(stdout) in my native executable directly after every printf() call, like the page suggested but it didn't work.