linux - 运行命令而不让我等待

标签 linux shell terminal sh calabash

我是 Shell Script Linux 的新手。
我正在使用 Android 进行自动化测试,所以我想运行一些 shell 脚本,如下所示:

  1. 开始通过adb(cmd1.sh)录屏
  2. 做场景测试然后停止/保存记录的文件(cmd2.sh)

不幸的是,当我运行 cmd1.sh 时,我必须等待 3 分钟才能运行 cmd2.sh。
这意味着我无法录制视频:sad:
这是我的运行命令内容:

run.sh文件内容:

./cmd1.sh $
./cmd2.sh

cmd1.sh文件内容:

adb shell screenrecord /sdcard/file.mp4

cmd2.sh文件内容:

calabash-android run app.apk

最后,我打开终端然后运行命令:

./run.sh

当然,视频是不能保存的,因为在cmd1.sh执行完之后,cmd2.sh正在运行!!!
在这一点上有人可以帮助我吗?
太感谢了 !

@Jrican 已更新
这是我可以播放视频录制的手动步骤。
1. 打开终端 A
2.运行命令1(开始录屏脚本)
3.打开其他终端B然后运行命令2
4. 命令 2 完成后,返回终端 A 然后按 Ctrl C。
5.确认/sdcard/file.mp4中的视频可以正常播放

我正在使用 MAC OSX Yosemite 10.10.5

最佳答案

简单的解决方案: run.sh文件内容:

./cmd1.sh &          # run this command in the background
./cmd2.sh            # run this command to completion 
kill -SIGINT %1      # send the interrupt signal to the first command (ctrl+c)

稍微更正确的解决方案: run.sh文件内容:

./cmd1.sh &            # run this command in the background
recPID=$!              # save the PID for this process for later
./cmd2.sh              # run this command to completion 
kill -SIGINT $recPID   # send the interrupt signal to the first command (ctrl+c)

关于linux - 运行命令而不让我等待,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32982510/

相关文章:

php - 通过 php 运行 npm install 脚本

linux - linux命令中的方括号后跟感叹号是什么意思?

mysql - 为什么我尝试创建 MySQL 数据库时权限被拒绝?

linux - 如何从 linux 连接到 FortiClient 提供的 SSL vpn

c - 如何访问共享库中可执行文件的全局变量(c - linux)

linux - 无法正确读取 Bash 中的文件

python - 从 Linux 终端执行包含子进程的 PyQt5 GUI 会导致 GUI 出现黑屏并卡住

linux - 在Linux中追踪进程需要什么样的权限

linux - 如何在 bash shell 中选择特定的行并在末尾回显

shell - shell 脚本中意外标记 `(' 附近出现语法错误