DESCRIPTION.rst 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. Delegator.py — Subprocesses for Humans 2.0
  2. =======================================
  3. .. image:: https://img.shields.io/pypi/v/delegator.py.svg
  4. :target: https://pypi.python.org/pypi/delegator.py
  5. .. image:: https://img.shields.io/pypi/l/delegator.py.svg
  6. :target: https://pypi.python.org/pypi/delegator.py
  7. .. image:: https://img.shields.io/pypi/wheel/delegator.py.svg
  8. :target: https://pypi.python.org/pypi/delegator.py
  9. .. image:: https://img.shields.io/pypi/pyversions/delegator.py.svg
  10. :target: https://pypi.python.org/pypi/delegator.py
  11. .. image:: https://img.shields.io/badge/SayThanks.io-☼-1EAEDB.svg
  12. :target: https://saythanks.io/to/kennethreitz
  13. **Delegator.py** is a simple library for dealing with subprocesses, inspired
  14. by both `envoy <https://github.com/kennethreitz/envoy>`_ and `pexpect <http://pexpect.readthedocs.io>`_ (in fact, it depends on it!).
  15. 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: ``|``.
  16. Basic Usage
  17. -----------
  18. Basic run functionality:
  19. .. code:: pycon
  20. >>> c = delegator.run('ls')
  21. >>> print c.out
  22. README.rst delegator.py
  23. >>> c = delegator.run('long-running-process', block=False)
  24. >>> c.pid
  25. 35199
  26. >>> c.block()
  27. >>> c.return_code
  28. 0
  29. Commands can be passed in as lists as well (e.g. ``['ls', '-lrt']``), for parameterization.
  30. Basic chain functionality:
  31. .. code:: pycon
  32. # Can also be called with ([['fortune'], ['cowsay']]).
  33. # or, delegator.run('fortune').pipe('cowsay')
  34. >>> c = delegator.chain('fortune | cowsay')
  35. >>> print c.out
  36. _______________________________________
  37. / Our swords shall play the orators for \
  38. | us. |
  39. | |
  40. \ -- Christopher Marlowe /
  41. ---------------------------------------
  42. \ ^__^
  43. \ (oo)\_______
  44. (__)\ )\/\
  45. ||----w |
  46. || ||
  47. Expect functionality is built-in too, on non-blocking commands:
  48. .. code:: pycon
  49. >>> c.expect('Password:')
  50. >>> c.send('PASSWORD')
  51. >>> c.block()
  52. Other functions:
  53. .. code:: pycon
  54. >>> c.kill()
  55. >>> c.send('SIGTERM', signal=True)
  56. # Only available when block=True, otherwise, use c.out.
  57. >>> c.err
  58. ''
  59. # Direct access to pipes.
  60. >>> c.std_err
  61. <open file '<fdopen>', mode 'rU' at 0x10a5351e0>
  62. Installation
  63. ------------
  64. ::
  65. $ pip install delegator.py
  66. ✨🍰✨