您的位置:首页 > 运维架构 > Shell

bat脚本调用Android中bash脚本,关闭bat后如何保持bash继续运行

2016-04-15 17:05 926 查看
例子:



目的是使bat脚本关闭后,startFloatWindow.sh继续运行。

这里使用a.sh脚本过渡,来后台启动startFloatWindow.sh。

关键点有两个:

1、a.sh中的&,表示后台启动新进程;

2、bat脚本中执行a.sh时,使用adb shell < temp.txt的方式,否则a.sh无法调用到startFloatWindow.sh



1、bat脚本内容如下:

adb push startFloatWindow.sh /data

adb push a.sh /data

adb shell "chmod 777 /data/startFloatWindow.sh"

adb shell "chmod 777 /data/a.sh"

echo cd /data >temp.txt

echo sh ./a.sh>>temp.txt

adb shell<temp.txt

2、a.sh脚本内容如下:

#!/system/bin/sh

echo "start run monitor 1..."

sh /data/startFloatWindow.sh&

3、startFloatWindow.sh脚本内容如下:

while true;

do

am startservice com.example.a/com.huawei.zhenshimoxing.FloatWindowService

sleep 1

echo "#"

done
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: