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

pip install 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.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

subprocrunner-0.16.0-py2.py3-none-any.whl (9.4 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: subprocrunner-0.16.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.7.1

File hashes

Hashes for subprocrunner-0.16.0.tar.gz
Algorithm Hash digest
SHA256 dee52b312d8576b89000d1d5a804757f391d1a78cff699a7d647ffe7f48d6821
MD5 e20b0f3f1994ed143fe119bbfcf81992
BLAKE2b-256 3ee9d70cf884d05b4f080a7c568e843b3e3731956574e4f9bcba978147e5524a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: subprocrunner-0.16.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.7.1

File hashes

Hashes for subprocrunner-0.16.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 912ecbb725c0da41aaebc2e5d53e8fc46c88baca252b63e8d881f431e073897c
MD5 025aabc0e5c59fe36bd44e4dbe58ec53
BLAKE2b-256 0d8a5e3b5df99bcfac8d98f9f154ce6e5f76dd9d18d2adce8f6598deec458e2b

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