All Projects → amitt001 → Delegator.py

amitt001 / Delegator.py

Licence: mit
Subprocesses for Humans 2.0.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Delegator.py

Sh
Python process launching
Stars: ✭ 5,963 (+277.64%)
Mutual labels:  subprocess
Flask-Shell2HTTP
Execute shell commands via HTTP server (via flask's endpoints).
Stars: ✭ 93 (-94.11%)
Mutual labels:  subprocess
python-executor
Programmer friendly subprocess wrapper
Stars: ✭ 88 (-94.43%)
Mutual labels:  subprocess
ansible-taskrunner
Ansible Taskrunner - ansible-playbook wrapper with YAML-abstracted python click cli options!
Stars: ✭ 14 (-99.11%)
Mutual labels:  subprocess
subprocess
No description or website provided.
Stars: ✭ 49 (-96.9%)
Mutual labels:  subprocess
bkt
bkt is a subprocess caching utility, available as a command line binary and a Rust library.
Stars: ✭ 117 (-92.59%)
Mutual labels:  subprocess
pytest-subprocess
Pytest plugin to fake subprocess.
Stars: ✭ 83 (-94.74%)
Mutual labels:  subprocess
subprocess
A C++ high level library for running shell processes
Stars: ✭ 189 (-88.03%)
Mutual labels:  subprocess
subprocess-tee
A subprocess.run drop-in replacement that supports a tee mode, being able to display output in real time while still capturing it. No dependencies needed
Stars: ✭ 31 (-98.04%)
Mutual labels:  subprocess
fsig
Send signals to a subprocess when files change
Stars: ✭ 16 (-98.99%)
Mutual labels:  subprocess

Delegator.py — Subprocesses for Humans 2.0

Delegator.py is a simple library for dealing with subprocesses, inspired by both envoy and pexpect (in fact, it depends on it!).

This module features two main functions delegator.run() and delegator.chain(). One runs commands, blocking or non-blocking, and the other runs a chain of commands, separated by the standard unix pipe operator: |.

Basic Usage

Basic run functionality:

>>> c = delegator.run('ls')
>>> print c.out
README.rst   delegator.py

>>> c = delegator.run('long-running-process', block=False)
>>> c.pid
35199
>>> c.block()
>>> c.return_code
0

Commands can be passed in as lists as well (e.g. ['ls', '-lrt']), for parameterization.

Basic chain functionality:

# Can also be called with ([['fortune'], ['cowsay']]).
# or, delegator.run('fortune').pipe('cowsay')

>>> c = delegator.chain('fortune | cowsay')
>>> print c.out
  _______________________________________
 / Our swords shall play the orators for \
 | us.                                   |
 |                                       |
 \ -- Christopher Marlowe                /
  ---------------------------------------
         \   ^__^
          \  (oo)\_______
             (__)\       )\/\
                 ||----w |
                 ||     ||

Expect functionality is built-in too, on non-blocking commands:

>>> c.expect('Password:')
>>> c.send('PASSWORD')
>>> c.block()

Other functions:

>>> c.kill()
>>> c.send('SIGTERM', signal=True)

# Only available when block=True, otherwise, use c.out.
>>> c.err
''

# Direct access to pipes.
>>> c.std_err
<open file '<fdopen>', mode 'rU' at 0x10a5351e0>

# Adjust environment variables for the command (existing will be overwritten).
>>> c = delegator.chain('env | grep NEWENV', env={'NEWENV': 'FOO_BAR'})
>>> c.out
NEWENV=FOO_BAR

Installation

$ pip install delegator.py

🍰

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].