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 2.7+ or 3.5+
Optional dependencies
- logbook
Logging using logbook 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-0.17.1.tar.gz
(11.7 kB
view details)
Built Distribution
File details
Details for the file subprocrunner-0.17.1.tar.gz
.
File metadata
- Download URL: subprocrunner-0.17.1.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b765a082b88bab9c76327ee260155ab6d4ece5e1406a5ddf2208a40cc37e8678 |
|
MD5 | 08757bb39ca13cbd1fbc18dba816e69d |
|
BLAKE2b-256 | da027702d609a5006d2cb3afdd0f6bbd9f807b272345d3fa2a9b913d850c2a4c |
File details
Details for the file subprocrunner-0.17.1-py2.py3-none-any.whl
.
File metadata
- Download URL: subprocrunner-0.17.1-py2.py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8debbbce859c7d23363fa45fe37773c743f20f3248222d70e9304fea189e872e |
|
MD5 | f3588a6550286b6a698039fc01426b87 |
|
BLAKE2b-256 | d27b9780e0f00c45d39e3c0e2e924659a279e67549d12bfdf035f5eebbcccb8d |