Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从android应用程序运行shell脚本_Android_Shell_Android Ndk - Fatal编程技术网

从android应用程序运行shell脚本

从android应用程序运行shell脚本,android,shell,android-ndk,Android,Shell,Android Ndk,我有一个这样的shell脚本 #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 现在,

我有一个这样的shell脚本

    #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
现在,该脚本位于/test/目录中。 我从一个c函数调用这个脚本,该函数是通过jni从android应用程序调用的。 我用这个函数调用我的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);
    }
}
现在,每当我从活动中调用这个systemcall函数时,它都无法执行脚本test.sh中的命令 如果我从普通的C源代码编译二进制代码并在控制台上执行该二进制代码,那么同样的脚本也可以工作。我曾尝试使用“chmod 777/test/test.sh”给予许可,但它仍然不起作用

任何帮助都将不胜感激。
谢谢。

如果您的shell解释器是
/system/bin/sh
,那么:

  • 对于以开头的shell脚本,将其设置为
    #/系统/bin/sh

  • 尝试使用解释器路径本身而不是
    字符来运行脚本


看起来。

是的,我也尝试过这个方法。但是仍然不起作用,顺便问一下,如果我用解释器代替解释器,会有什么不同。性格我正在用这个。因为我需要当前控制台中的状态变量,否则我将无法使用它。为什么需要状态变量?也许您可以将它放在test.sh中并简化您的命令,以最小化可能出现问题的地方。