I am writing a C++ code to execute 'top' command in android device. This is the code I use.
using namespace std; int main() { char buffer[1024]; string result; system("top -n 1 | head -n 4 | tail -n 3"); FILE *memcpu= popen("top -n 1 | head -n 4 | tail -n 3","r"); while (!feof(memcpu)) { if (fgets(buffer, 1024, memcpu) != NULL) result+=buffer; } cout<<"result you need\n"<<result; } I want to run this file in adb device. Hence I build the program using command
arm-linux-gnueabi-g++ -static -march=armv7-a name.cpp -o test When I run the program, the string result is empty.
I tested the program by including system("top -n 1"); line in the program. But I am not getting any output from adb shell (empty string).
I build the same program using g++ and run in linux pc. And at that time I am getting the correct output. What might be the reason that I am not getting desired output in adb shell from android device?
c++code usingJNIor any other way?