android - 如何从另一个 shell 脚本将一个 shell 脚本作为进程启动

标签 android linux bash shell adb

我想从主机上运行的 script1.sh 执行此操作

#!/bin/sh

# adb shell "sh /sdcard/script2.sh &"

script2.sh 位于 Android 设备上的/sdcard/文件夹内。

我希望 script2.sh 继续在 Android 上运行。 script2.sh 有无限循环。 但上面的命令不起作用。 script1.sh 退出后 script2.sh 就会停止。

我也尝试过

# adb shell "exec sh /sdcard/script2.sh &"

但这也行不通。

最佳答案

在父 shell 脚本中,提取子进程 script2.sh 的 pid。 然后使用 wait 系统命令等待其完成。

wait <PID>

引用此link了解更多详情。

关于android - 如何从另一个 shell 脚本将一个 shell 脚本作为进程启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36854686/

相关文章:

c# - Xamarin for Android(Mono for Android)与原生 Android 开发相比如何?

android定位服务GPS精度取值范围

java - 将文件复制到HDFS时,如何控制该文件驻留在哪些节点上?

linux - 前置符号链接(symbolic link)文件名

bash - 是否可以获取函数体中的函数名?

bash - Go 和 MongoDB 连接不适用于紧急日志 "no reachable server"

Android:突出显示在图库中选择的图像

Android VectorDrawable 未显示在布局中

c++ - 错误: ‘ ’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

linux - 如何在此代码中提高 PS1 的生成速度?