A class to execute ADB (Android Debug Bridge) commands on multiple operating systems.
Tested against Windows 10/Android/Linux / Python 3.11 / Anaconda
pip install adbshellexecuter
A class to execute ADB (Android Debug Bridge) commands on multiple operating systems.
This class provides methods to run ADB commands with and without capturing stdout and stderr,
as well as creating non-blocking subprocesses. It handles different operating system environments
such as Windows, Linux, macOS, and Android, providing a unified interface for ADB command execution.
Òn Android, the "adb shell" part is completely ignored, instead a subshell (sh) is used to execute commands
Args:
adb_path (str): The path to the adb executable.
device_serial (str): The serial number of the device.
standard_kwargs_windows (tuple): Standard kwargs for Windows.
standard_kwargs_linux (tuple): Standard kwargs for Linux.
standard_kwargs_darwin (tuple): Standard kwargs for macOS.
standard_kwargs_android (tuple): Standard kwargs for Android.
# Example usage
import shutil
from adbshellexecuter import UniversalADBExecutor
device_serial = "127.0.0.1:5645"
adb_path = shutil.which("adb")
adbshell = UniversalADBExecutor(
adb_path=adb_path,
device_serial=device_serial,
standard_kwargs_windows=(
("env", os.environ),
("shell", False),
("startupinfo", startupinfo),
(
"creationflags",
creationflags,
),
("start_new_session", True),
),
standard_kwargs_linux=(
("env", os.environ),
("shell", True),
),
standard_kwargs_darwin=(
("env", os.environ),
("shell", True),
),
standard_kwargs_android=(
("env", os.environ),
("shell", True),
),
)
adbshell.non_shell_adb_commands_without_s_serial(
[
"connect",
device_serial,
],
)
p1 = adbshell.shell_without_capturing_stdout_and_stderr(
"mkdir -p '/sdcard/testfiles'", cwd="c:\\windows"
)
p2 = adbshell.shell_with_capturing_import_stdout_and_stderr("ls /sdcard", check=True)
p3 = adbshell.non_shell_adb_commands_with_s_serial(
r'push "C:\writetext.txt" /sdcard/testfiles'
)
nonblock = adbshell.create_non_blocking_proc(
debug=True, ignore_exceptions=False, bufsize=1
)
nonblock.extra_data_to_print_stderr = "stderr: "
nonblock.extra_data_to_print_stdout = "stdout: "
nonblock.stdinwrite("ls")
nonblock.stdinwrite("ls /sdcard/testfiles")
print(nonblock.stdout_results)
nonblock.stdinwrite("ls /sdcardbbbbbbbb/testfiles")
print(nonblock.stderr_results)
nonblock.stdinwrite("su")
commandok = nonblock.stdinwrite("ls /system")
print(f"{commandok=}")
print(nonblock.stderr_results)
commandok = nonblock.stdinwrite("ls /system")
nonblock.print_stdout = False
nonblock.print_stderr = False
print(nonblock.stderr_results)
nonblock.kill()
commandok2 = nonblock.stdinwrite("ls /system")
p4 = adbshell.shell_without_capturing_stdout_and_stderr(
command="while true;do ls;sleep 1;done",
debug=True,
ignore_exceptions=True,
timeout=10,
)
Metadata
Release files for adbshellexecuter 0.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| adbshellexecuter-0.12.tar.gz | 8.2 kB | Without provenance | Details for adbshellexecuter-0.12.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| adbshellexecuter-0.12-py3-none-any.whl | Python 3 | none | any | Details for adbshellexecuter-0.12-py3-none-any.whl |
Total release size: 18.2 kB
Release files / adbshellexecuter-0.12.tar.gz
| Download URL | adbshellexecuter-0.12.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2647e9102992af7b3de2040b836989d1fda311bc28c8519951700c8c5bcefb43
|
|
BLAKE2b-256 checksum How to use checksums |
b1a1f1e56c8a6a36e83600691555039c4ae7c832e271b928c465ffc7a3e6b9cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / adbshellexecuter-0.12-py3-none-any.whl
| Download URL | adbshellexecuter-0.12-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
678550aa21e7a535ac55da6bf76ed3dcef345c78cd76a0334ba2f9634c71be91
|
|
BLAKE2b-256 checksum How to use checksums |
26d29bcd77e687662dc1251054337ae01bb065f3820dbb0cc70f3b9ca57243c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Security for adbshellexecuter 0.12
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.