system is returning error 127 when called from c++

2019-02-28 09:27发布

问题:

The command "am start -n packagename/.activityname" has to be run in adb shell and is to be included in C++ program

I added the line system("am start -n packagename/.activityname") in my C++ program and when the program is run in adb shell, the system command is returning error code 127 and the shell command is not running

compiler used : arm-linux-none-gnueabi-g++

Its working when i used the g++ compiler

Is the problem with the compiler or with the path?

回答1:

system() will not, in fact, work properly from programs with set-user-ID or set-group-ID privileges on systems on which /bin/sh is bash version 2, since bash 2 drops privileges on startup linux.die.net/man/3/system

Instead of system i used execl("/system/bin/sh","sh","test.sh")

where test.sh has am start -n packagename/.activityname and it works