2

I have one shell script like this,

    #Script name : test.sh
    mkdir /boot
    mount -t vfat /dev/block/mmcblk0p1 /boot
    cp file1 /boot
    umount /boot

    mkdir -p /test1/test2/test3
    cp file2 /test1/test2
    cp file3 /test1/test2/test3
    STATUS=TRUE

Now this script is located in /test/ directory. I am calling this script from a c function which is called from android application via jni. I am using this function to call my script in C

void Java_com_ndkdemo_NDKdemoActivity_systemcall(JNIEnv * env, jobject obj) {
    fp = popen(". /test/./test.sh; echo STATUS=$STATUS","r");
    while (fgets(buffer, sizeof (buffer), fp) != 0)
    {
        LOGD("%s",buffer);
    }
}

Now when ever i call this systemcall function from my activity, it is not able to execute the commands inside the script test.sh The same script is working if i am compiling a binary from normal C source code and execute that binary on console. I have tried to give permission with "chmod 777 /test/test.sh" but still it's not working.

Any help will be appreciated. Thank you.

user1310041
  • 31
  • 1
  • 5

1 Answers1

1

If your shell interpreter is /system/bin/sh then:

  • for shell scripts that start with a shebang, make it #!/system/bin/sh

  • try to use the interpreter path itself instead of the . character to run your script

And it seems that popen may not work in older versions of Android.

Community
  • 1
  • 1
gfour
  • 959
  • 6
  • 9
  • Yup tried this things too..but still not working, by the way what will the difference if i will use interpreter instead of . character? I am using this . because i need that STATUS variable in current console other wise i will not be able to use it. – user1310041 Jun 01 '12 at 11:19
  • Why do you need the STATUS variable? Maybe you can put it inside your test.sh and simplify your command, to minimize the places where a problem may appear. – gfour Jun 01 '12 at 11:49