All
Here i want to run .sh file via system call in android NDK.
I able to run cp,rm command via system call. but sh command is not working via system call.
I also installed busy-box on android.I am using below code.I set all permission on test.sh.
Code :
#include <stdlib.h>
#include <stdio.h>
#include <android/log.h>
#include <jni.h>
#define LOG_TAG "Demo"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
void Java_com_ndkdemo_NDKdemoActivity_systemcall(JNIEnv * env, jobject obj) {
int result;
result = system("cp /mnt/sdcard/test /Download");
LOGD("result is cp %d", result);
result = system("sh ./test.sh");
LOGD("result of test.sh is %d", result);
}
Output :
result is cp 0.
result of test.sh is 0.
Here i am getting 0 in system("sh ./test.sh"); but not started the test.sh script.
cant get output "Hi" on console.
test.sh contains
#!/system/bin/
echo "Hi"
If i am executing direct command on prompt than its working fine and its given output "Hi" on console.
Please Help me to figure out this issue.
Thanks
Where are you expecting to see the “echo”? By default, android sends stdout to /dev/null.
According to the documentation you can redirect stdout and stderr to the log (so it will show up in logcat) using the following commands:
Now you may see your echo in
adb logcat.