adb wait-for-devices超时/非阻塞?

时间:2014-11-18 02:34:21

标签: android timeout adb nonblocking

调用“adb wait-for-devices”时有没有办法超时?

情景:

adb reboot
adb wait-for-devices (timeout listed here - if possible)
**if times out: echo timed out**
**else**
adb root
adb wait-for-devices

2 个答案:

答案 0 :(得分:3)

在Bash,

timeout <time_in_seconds> adb wait-for-any-device

Ex:下面的命令会等待40秒来扫描adb设备,并会在成功时返回命令的退出代码,或者在超时时返回124,或者在命令失败时退出命令代码。

timeout 40 adb wait-for-any-device

答案 1 :(得分:0)

这个问题的目的是为了自动化,所以我找到了一个使用Perl报警功能的临时解决方案:

sub ADB_Wait_Timeout
{
    eval 
    {
        local $SIG{ALRM} = sub { die "Timeout\n" };
        alarm 60;
        system("adb wait-for-devices");
        alarm 0;
    };
    if ($@) 
    {
        print "Device did not come up\n";
    }
}

关于如何使用超时进行系统调用,有类似的答案: https://stackoverflow.com/a/2563551/3491654