Skip to main content

A Python wrapper library for subprocess module.

Project description

Summary

A Python wrapper library for subprocess module.

PyPI package version Supported Python versions Linux/macOS CI status Windows CI status Test coverage

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.4+

Optional dependencies

  • logbook
    • Logging using logbook if the package installed

Test dependencies

Project details


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.16.1.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

subprocrunner-0.16.1-py2.py3-none-any.whl (9.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file subprocrunner-0.16.1.tar.gz.

File metadata

  • Download URL: subprocrunner-0.16.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

Hashes for subprocrunner-0.16.1.tar.gz
Algorithm Hash digest
SHA256 367e8b2ce9e264ac8dc9b8a0ec961d31f5752bb1e005213cfa47642a529afb89
MD5 cdef8092040ee18b5057e9af215737b7
BLAKE2b-256 b76b9ddd959469f2d02f6e52d4d7b16200542928ae5d90e26c840bf3c1da882b

See more details on using hashes here.

File details

Details for the file subprocrunner-0.16.1-py2.py3-none-any.whl.

File metadata

  • Download URL: subprocrunner-0.16.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.5 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

Hashes for subprocrunner-0.16.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9eea770ea8a61bcd2c026ca2006daa3803358ac7aa0db08001a060b036b8a68d
MD5 8b26d5c4a112edcb73e18267c36ffe0f
BLAKE2b-256 3383528266a794b00e346efcffa436a083fb0c2e70b72efe391a761e90a54efc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page