我希望有人能夠幫助我爲什麼我的while循環不會退出時,我附加兩個Android設備。Perl循環等待adb設備陣列
在SO研究的幫助下,我設法拼湊了下面的代碼,但是我添加了一個while循環來等待對Android'adb devices'命令的響應。我期待在此while while循環中等待兩個Android設備通過USB連接到我的PC,或者當兩個連接的設備打開時。我的代碼編譯好了,並且能夠在設備已經打開並連接時通過while循環工作,但是當我使用USB電纜將腳本啓動到android設備斷開連接時,然後幾秒鐘後插入USB連接在我的電腦中,腳本仍然在循環中。我在Windows 7上使用最新的Strawberry Perl運行此腳本。
任何指導都將不勝感激。
下面的代碼...
use strict;
use warnings qw(all);
use IPC::Run3;
use Carp qw(croak confess cluck);
use Data::Dumper;
my @devices = get_devices();
my $devicesattached = "";
while ([email protected]){
get_devices();
print ".";
sleep (1);
last if @devices;
}
print "\n\tDevice 1 is $devices[0]";
print "\n\tDevice 2 is $devices[1]\n";
sub get_devices {
my $adb_out;
run3 ["adb", "devices"], undef, \$adb_out, undef;
$? and cluck "Warning: non-zero exit status from adb ($?)";
my @res = $adb_out =~ m/^([[:xdigit:]]+) \s+ device$/xmg;
return wantarray ? @res : \@res;
}
非常感謝, MikG
一旦你進入循環,你永遠不會改變'@ devices'。 – ThisSuitIsBlackNot
@ThisSuitIsBlackNot:您的評論是正確的,應該寫爲答案。 – Borodin
@Borodin工作。 – ThisSuitIsBlackNot