Skip to main content

A Python wrapper library for subprocess module.

Project description

subprocrunner

Summary

A Python wrapper library for subprocess module.

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/macOS https://img.shields.io/appveyor/ci/thombashi/subprocrunner/master.svg?label=Windows https://coveralls.io/repos/github/thombashi/subprocrunner/badge.svg?branch=master

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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

subprocrunner-0.15.6-py2.py3-none-any.whl (8.5 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

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

File hashes

Hashes for subprocrunner-0.15.6.tar.gz
Algorithm Hash digest
SHA256 bb2cacfb8be6d72253c55c3f2d10e120dd7ec7651e8c9aef38326894adf910a2
MD5 123823f37038c08c672add33e1522b36
BLAKE2b-256 9456cb72a34bfb8fcc6f371d56a9d44800c1324172a3ba416c6b889ed39a0c15

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for subprocrunner-0.15.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 006dc0729e221efbdfded9cdefaab6990c80c4f82c54cd500e06837e75e47a49
MD5 1920aa4d1704acfd3db73af909ea07e6
BLAKE2b-256 636c9b14f3be7e6e28011cfb4e1c53967bb0fa13b5da702249567bacf9d49b61

See more details on using hashes here.

Supported by

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