Skip to main content

Subprocesses for Humans 2.0.

Project description — Subprocesses for Humans 2.0

.. image::

.. image::

.. image::

.. image::

.. image::☼-1EAEDB.svg

**** 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 ```` 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: ``|``.

If you're interested in financially supporting Kenneth Reitz open source, consider `visiting this link <$KennethReitz>`_. Your support helps tremendously with sustainability of motivation, as Open Source is no longer part of my day job.

Basic Usage

Basic run functionality:

.. code:: pycon

>>> c ='ls')
>>> print c.out

>>> c ='long-running-process', block=False)
>>> c.block()
>>> c.return_code

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

Basic chain functionality:

.. code:: pycon

# Can also be called with ([['fortune'], ['cowsay']]).
# or,'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:

.. code:: pycon

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

Other functions:

.. code:: pycon

>>> 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



$ pip install


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size (5.0 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size (6.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page