Reputation: 71
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?
Upvotes: 1
Views: 1165
Reputation: 71
When you build the program using command
arm-linux-gnueabi-g++ -static -march=armv7-a name.cpp -o test
a static binary is created. In order to link the libraries in android, the program must be built using android ndk build. And that solved the problem for me.
Upvotes: 1