Skip to main content

A Python wrapper library for subprocess module.

Project description

subprocrunner

https://badge.fury.io/py/subprocrunner.svg https://img.shields.io/pypi/pyversions/subprocrunner.svg https://img.shields.io/travis/thombashi/subprocrunner/master.svg?label=Linux https://img.shields.io/appveyor/ci/thombashi/subprocrunner/master.svg?label=Windows https://coveralls.io/repos/github/thombashi/subprocrunner/badge.svg?branch=master

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

pip install subprocrunner

Dependencies

Python 2.7+ or 3.4+

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

Uploaded Source

Built Distribution

subprocrunner-0.11.0-py2.py3-none-any.whl (8.3 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

File hashes

Hashes for subprocrunner-0.11.0.tar.gz
Algorithm Hash digest
SHA256 43448fa775cd400f505c44a3ba0cf62006cb4c73d886196c7bd82794490e4d27
MD5 62679dd22b877435bf4f5ca5ef1cb797
BLAKE2b-256 1f3b18daaac889fedf0826f0aba87305ac0bd67bc71f4c84c02c85729e8fa0d3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for subprocrunner-0.11.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 977307a7f051dee243bd402b9c73554ba56839781a3f700bbf18e343b2fdc1f9
MD5 b1aee580f4ba0997f5853c82682891a4
BLAKE2b-256 d547c910733627750805d9409376fa75fcc5088312820fa08f65f21cb0ce6103

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