Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Subprocesses for Humans 2.0.

License

NotificationsYou must be signed in to change notification settings

amitt001/delegator.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Delegator.py is a simple library for dealing with subprocesses, inspiredby bothenvoy andpexpect (in fact, it depends on it!).

This module features two main functionsdelegator.run() anddelegator.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.outREADME.rst   delegator.py>>> c= delegator.run('long-running-process',block=False)>>> c.pid35199>>> c.block()>>> c.return_code0

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.outNEWENV=FOO_BAR

Installation

$ pip install delegator.py

✨🍰✨

About

Subprocesses for Humans 2.0.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors21

Languages


[8]ページ先頭

©2009-2025 Movatter.jp