NAME
Net::ADB::Shell::Result - Result of a shell command run on an Android device
SYNOPSIS
use Net::ADB;
my $adb = Net::ADB->new;
my $res = $adb->shell_v2(command => 'ls /sdcard');
if ($res->is_success) {
say for $res->stdout_lines;
}
else {
say STDERR $res->stderr;
}
say $res->exit_code; # 0
say $res->duration; # 0.084
# Croak unless the command succeeded
my $output = $adb->shell_v2(command => 'getprop')->assert_success->stdout;
DESCRIPTION
Net::ADB::Shell::Result holds the result of a command run with "shell_v2" in Net::ADB or "shell" in Net::ADB::Device: output, error output, exit code and duration.
The instance is a blessed hash reference, so the fields can also be read directly ($res->{stdout}, $res->{stderr}, $res->{exit}).
CONSTRUCTOR
new
my $res = Net::ADB::Shell::Result->new(
command => 'ls /sdcard',
stdout => "Download\nPictures\n",
stderr => '',
exit => 0,
duration => 0.084
);
Create a new Net::ADB::Shell::Result instance. It is created by "shell_v2" in Net::ADB, so there is usually no need to call new directly.
Allowed parameters:
command, the command.stdout, the output.stderr, the error output.exit, the exit code.duration, the duration in seconds.
METHODS
command
Return the command.
stdout
Return the output of the command, as bytes.
stderr
Return the error output of the command, as bytes.
exit_code
Return the exit code of the command (0 to 255).
duration
Return the duration of the call in seconds, with decimals. It includes the connection to the ADB server and the transfer of the output, not only the execution of the command.
is_success
Return 1 if the exit code is 0, 0 otherwise.
is_error
Return 1 if the exit code is not 0, 0 otherwise.
assert_success
my $output = $res->assert_success->stdout;
Return the instance if the command succeeded, otherwise croak with the command, the exit code and the error output:
Command 'cat /no/such/file' failed (exit 1): cat: /no/such/file: No such file or directory
Note that some commands exit with a non-zero code in normal cases (e.g. grep with no match).
stdout_lines
for my $line ($res->stdout_lines) { ... }
Return the lines of the output, without the newlines (an array reference in scalar context).
lines
Alias of "stdout_lines".
stderr_lines
Return the lines of the error output, without the newlines (an array reference in scalar context).
TO_JSON
Helper method for JSON modules (e.g. JSON::PP).
use JSON::PP;
say JSON::PP->new->canonical->convert_blessed->encode($res);
# {"command":"ls /sdcard","duration":0.084,"exit":0,"stderr":"","stdout":"Download\nPictures\n"}
SEE ALSO
SUPPORT
Bugs / Feature Requests
Please report any bugs or feature requests through the issue tracker at https://github.com/giterlizzi/perl-Net-ADB/issues. You will be notified automatically of any progress on your issue.
Source Code
This is open source software. The code repository is available for public review and contribution under the terms of the license.
https://github.com/giterlizzi/perl-Net-ADB
git clone https://github.com/giterlizzi/perl-Net-ADB.git
AUTHOR
Giuseppe Di Terlizzi <gdt@cpan.org>
LICENSE AND COPYRIGHT
This software is copyright (c) 2026 by Giuseppe Di Terlizzi.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)