A Python wrapper library for subprocess module.
Project description
Summary
A Python wrapper library for subprocess module.
Examples
Execute a command
- Sample Code:
from subprocrunner import SubprocessRunner runner = SubprocessRunner(["echo", "test"]) print(runner) print(f"return code: {runner.run()}") print(f"stdout: {runner.stdout}") runner = SubprocessRunner(["ls", "__not_exist_dir__"]) print(runner) print(f"return code: {runner.run()}") print(f"stderr: {runner.stderr}")
- Output:
SubprocessRunner(command='echo test', returncode='not yet executed') return code: 0 stdout: test SubprocessRunner(command='ls __not_exist_dir__', returncode='not yet executed') return code: 2 stderr: ls: cannot access '__not_exist_dir__': No such file or directory
Execute a command with retry
- Sample Code:
from subprocrunner import Retry, SubprocessRunner SubprocessRunner(command).run(retry=Retry(total=3, backoff_factor=0.2, jitter=0.2))
dry run
Commands are not actually run when passing dry_run=True to SubprocessRunner class constructor.
- Sample Code:
from subprocrunner import SubprocessRunner runner = SubprocessRunner("echo test", dry_run=True) print(runner) print(f"return code: {runner.run()}") print(f"stdout: {runner.stdout}")
- Output:
SubprocessRunner(command='echo test', returncode='not yet executed', dryrun=True) return code: 0 stdout:
Get execution command history
- Sample Code:
from subprocrunner import SubprocessRunner SubprocessRunner.clear_history() SubprocessRunner.is_save_history = True SubprocessRunner(["echo", "hoge"]).run() SubprocessRunner(["echo", "foo"]).run() print("\n".join(SubprocessRunner.get_history()))
- Output:
echo hoge echo foo
Get a command information
>>> from subprocrunner import Which
>>> which = Which("ls")
>>> which.is_exist()
True
>>> which.abspath()
'/usr/bin/ls'
>>> which
command=ls, is_exist=True, abspath=/usr/bin/ls
Installation
Install from PyPI
pip install subprocrunner
Install from PPA (for Ubuntu)
sudo add-apt-repository ppa:thombashi/ppa sudo apt update sudo apt install python3-subprocrunner
Dependencies
Optional dependencies
- loguru
Used for logging if the package installed
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
subprocrunner-1.6.0.tar.gz
(14.2 kB
view details)
Built Distribution
File details
Details for the file subprocrunner-1.6.0.tar.gz
.
File metadata
- Download URL: subprocrunner-1.6.0.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c1e928db282e7453853744290908d04047a8fb3b49ff1e7f8284e6a3be3a810 |
|
MD5 | 1b551932c4da813271e0177b00222647 |
|
BLAKE2b-256 | 32a3030432c2e2f28ede2e1855136e82f1cb8b599274ef0fe0aee09dcb6eb3fe |
File details
Details for the file subprocrunner-1.6.0-py3-none-any.whl
.
File metadata
- Download URL: subprocrunner-1.6.0-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ed357578c2b11b54ed2bce15fc169adf71349830a11a333d16f6057e33e1c81 |
|
MD5 | 60c6191995e14d9515aa91d3fab0f87b |
|
BLAKE2b-256 | 062679d78eed5d1c176ac57b8bf7c36d6bee8067f98b34edbf7f38b89fb6f07a |