Perl脚本来存储设备序列号并使用adb安装apk [英] Perl script to store device serial number and install apk using adb
问题描述
我要做的是捕获设备序列号并将其存储在数组或列表中。然后我想在连接到系统的各种android设备上安装我的apk。我正在尝试制作一个可以为我做到这一点的perl脚本。
What I want to do is to capture the device serial numbers and store them in an array or list. Then I want to install my apk on various android devices that I connect to my system.I am trying to make a perl script that can do this for me.
类似
if($ostype eq 'MSWin32') {
system("title Android");
$adbcommand_devices = "adb devices";
$adbcommand_install = "adb -s xxxxxxxx install HelloWorld.apk";
}
if(`adb -s xxxxxxxx get-state` =~ m/device/i) {
system($adbcommand_devices);
system($adbcommand_install);
}
else {
print "Device is offline\n";
}
序列号应来自当前连接的设备。
The serial number should come from the currently connected device.
推荐答案
以下是使用 IPC :: Run3
:
Here is an example of just the adb devices
command using IPC::Run3
:
use strict;
use warnings qw(all);
use IPC::Run3;
use Carp qw(croak confess cluck);
use Data::Dumper;
my $ADB_PATH = '/path/to/adb'; # EDIT THIS
my @devices = get_devices();
print Dumper(\@devices);
exit 0;
# subs
sub get_devices {
my $adb_out;
run3 [$ADB_PATH, '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;
}
对于很多此类,您可以使用 qx
/
。例如,您可以将 run3
替换为 my $ adb_out =`$ ADB_PATH devices`;
(因为您没有需要将任何东西传递给它,只需传递出去,也不需要避免使用shell。)
For a lot of this, you may be able to use qx
/``
as well. E.g., you could replace the run3
with my $adb_out = `$ADB_PATH devices`;
(because you didn't need to pass anything in to it, just out, and also didn't need to avoid the shell.)
这篇关于Perl脚本来存储设备序列号并使用adb安装apk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!