Is there a way to have a timeout when calling "adb wait-for-devices"?
Scenario:
adb reboot
adb wait-for-devices (timeout listed here - if possible)
**if times out: echo timed out**
**else**
adb root
adb wait-for-devices
Is there a way to have a timeout when calling "adb wait-for-devices"?
Scenario:
adb reboot
adb wait-for-devices (timeout listed here - if possible)
**if times out: echo timed out**
**else**
adb root
adb wait-for-devices
In Bash,
timeout <time_in_seconds> adb wait-for-any-device
Ex: Below command waits for 40 seconds to scan for adb devices, and will return the exit code of the command, on success, or 124 on timeout, or exit code of command on command failure.
timeout 40 adb wait-for-any-device
The purpose of this question was for Automation, so I found a temporary solution using Perl's Alarm feature:
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";
}
}
There are similar answers on how to do system calls with a timeout: https://stackoverflow.com/a/2563551/3491654