2011年1月11日 星期二

Run shell script from C code under android

follow this

I use system to launch shell script

return message
call system. return value is 7f00

source code
#include
#include

int main(int argv, char* agrvc)
{
int ret = system("/mnt/sdcard/Hello.sh");
printf("call system. return value is %x", ret);
}

使用execv
可以正確執行到shell script

source code
#include
#include

int main(int arg, char* agrc)
{
//int ret = system("/mnt/sdcard/Hello.sh");
char *argv[]={"bash", "/mnt/sdcard/Hello.sh", NULL};
int ret = execv("/system/bin/bash", argv);

printf("call system. return value is %x", ret);
}

螢幕顯示
This is shellscript. Hello!

此外
run executable file
你可以參考此篇


透過Facebook分享

沒有留言: