A class to execute ADB (Android Debug Bridge) commands on multiple operating systems.
Project description
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,
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
adbshellexecuter-0.12.tar.gz
(8.2 kB
view details)
Built Distribution
File details
Details for the file adbshellexecuter-0.12.tar.gz
.
File metadata
- Download URL: adbshellexecuter-0.12.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2647e9102992af7b3de2040b836989d1fda311bc28c8519951700c8c5bcefb43 |
|
MD5 | fe8e460182326031c17ffd31786772ef |
|
BLAKE2b-256 | b1a1f1e56c8a6a36e83600691555039c4ae7c832e271b928c465ffc7a3e6b9cd |
File details
Details for the file adbshellexecuter-0.12-py3-none-any.whl
.
File metadata
- Download URL: adbshellexecuter-0.12-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 678550aa21e7a535ac55da6bf76ed3dcef345c78cd76a0334ba2f9634c71be91 |
|
MD5 | 28183ec0a06d7e76d8dbb3911c06b045 |
|
BLAKE2b-256 | 26d29bcd77e687662dc1251054337ae01bb065f3820dbb0cc70f3b9ca57243c6 |