gpt4 book ai didi

android - Shell脚本等待命令永远不会结束

转载 作者:太空宇宙 更新时间:2023-11-04 05:13:18 26 4
gpt4 key购买 nike

我正在编写一个脚本文件来从 shell 运行 Android 测试用例,我有一些 Android ADB 命令来运行脚本文件中的测试用例来执行,并让 wait 等待第一组测试用例在第一组测试用例结束后几秒钟结束。

脚本文件: fragment

#!/bin/bash
# set up code

#First set of test cases
adb -s emulator-5554 shell am instrument -w com.android.demo.app.tests1/android.support.test.runner.AndroidJUnitRunner &
adb -s emulator-5556 shell am instrument -w com.android.demo.app.tests2/android.support.test.runner.AndroidJUnitRunner &
wait # Second set test cases does not started because this **wait** never ends

#Second set of test cases
adb -s emulator-5554 shell am instrument -w com.android.demo.app.tests3/android.support.test.runner.AndroidJUnitRunner &
adb -s emulator-5556 shell am instrument -w com.android.demo.app.tests4/android.support.test.runner.AndroidJUnitRunner &
wait

echo '--------- Test cases done --------------'

如果我运行脚本,则会执行其运行第一组(test1 和 test2)案例,并且等待永远不会结束以启动第二组测试案例但Android工作室(Android的IDE)表示测试用例已为第一个设置的test1和test2完成。注意:ADB 在 Android 模拟器上运行测试用例。请帮助我解释为什么我没有等待结束。

最佳答案

我使用以下代码进行了测试:

#!/bin/bash
#set 1
ls -la &
ls -la &
wait # wait here

#set 2
pwd &
pwd &
wait # wait here

代码按预期完美运行,没有中断或错误。

请尝试运行 test3 和 test4,而不运行 test1 和 test2,看看这是否有帮助。

编辑:另外,来自另一个答案 here您应该能够捕获上一个命令的 PID (processID),并使用该 PID 作为等待参数。

关于android - Shell脚本等待命令永远不会结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52680051/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com