mirror of
https://github.com/kennethreitz-archive/procs.git
synced 2026-06-05 23:30:18 +00:00
14d54d88b2
- Renames standard streams to ones without the underscore. - Retains subprocess' way of doing returncode as opposed to exit_code - t.py doesn't make sense, calling it usage.py
59 lines
1.1 KiB
ReStructuredText
59 lines
1.1 KiB
ReStructuredText
Pipes: Python, Processes, and... Pipes
|
|
======================================
|
|
|
|
Python's Subprocess module is well designed for lower functions. Pipes is designed
|
|
to encourage higher functions.
|
|
|
|
|
|
Ideas
|
|
-----
|
|
|
|
- Simple shelling out, allow argument seperation.
|
|
- command timeouts
|
|
- Process monitoring
|
|
- programatically compose a chain of streams.
|
|
- process call timeouts
|
|
- >>> uptime.stdout >> cowsay.stdin
|
|
|
|
Usage
|
|
-----
|
|
|
|
Simple Usage::
|
|
|
|
>>> import pipes
|
|
|
|
>>> c = pipes.run('uptime')
|
|
>>> c.returncode
|
|
0
|
|
>>> c.ok
|
|
True
|
|
>>> print c.stdout
|
|
16:08 up 1:16, 7 users, load averages: 1.02 1.90 1.75
|
|
|
|
|
|
Advanced Usage::
|
|
|
|
>>> chain = pipes.chain()
|
|
>>> uptime = chain.process('uptime')
|
|
>>> cowsay = chain.process('cowsay')
|
|
>>> chain.link(uptime.stdout, cowsay.stdin)
|
|
>>> chain.start(wait=True)
|
|
>>> chain.wait()
|
|
|
|
|
|
>>> from pipes import ProcessHandler
|
|
|
|
class MyCommmand(ProcessHandler):
|
|
|
|
def __init__(self):
|
|
pass
|
|
|
|
def on_start(self):
|
|
pass
|
|
|
|
def on_exit(self):
|
|
pass
|
|
|
|
def on_crash(self):
|
|
pass
|