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("command: {:s}".format(runner.command)) print("return code: {:d}".format(runner.run())) print("stdout: {:s}".format(runner.stdout)) runner = SubprocessRunner("ls __not_exist_dir__") print("command: {:s}".format(runner.command)) print("return code: {:d}".format(runner.run())) print("stderr: {:s}".format(runner.stderr))
- Output:
command: echo test return code: 0 stdout: test command: ls __not_exist_dir__ return code: 2 stderr: ls: cannot access '__not_exist_dir__': No such file or directory
dry run
- Sample Code:
from subprocrunner import SubprocessRunner runner = SubprocessRunner("echo test", dry_run=True) print("command: {:s}".format(runner.command)) print("return code: {:d}".format(runner.run())) print("stdout: {:s}".format(runner.stdout))
- Output:
command: echo test 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
Python 3.5+
Optional dependencies
- loguru
Used for logging if the package installed
Test dependencies
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.2.0.tar.gz
(12.3 kB
view details)
Built Distribution
File details
Details for the file subprocrunner-1.2.0.tar.gz
.
File metadata
- Download URL: subprocrunner-1.2.0.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e5c7463f47b668257131fd70b55cbfe02cd32d2a5dc4377f6c2aaeb8352f8ba |
|
MD5 | 2cd7f28d6e6357e15ac2e8284be9bc17 |
|
BLAKE2b-256 | ccc43f707bc5c4de4c335f473686caa461fedc8c91f2672fa6a5b23238fad3d1 |
File details
Details for the file subprocrunner-1.2.0-py3-none-any.whl
.
File metadata
- Download URL: subprocrunner-1.2.0-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 208a47f5c29c07b09f9b0dce76d23f3dfc0c072c10c8a31760b5f6adf65794ab |
|
MD5 | f044c8a5d942994022811d5592b3cc62 |
|
BLAKE2b-256 | 5df21ff3316d06a0b364eb0fe028549fa4701246196c16e33a40929e25ea4474 |