libbe.util.subproc

Functions for running external commands in subprocesses.

exception libbe.util.subproc.CommandError(command, status, stdout=None, stderr=None)
class libbe.util.subproc.Pipe(cmds, stdin=None)

Simple interface for executing POSIX-style pipes based on the subprocess module. The only complication is the adaptation of subprocess.Popen._comminucate to listen to the stderrs of all processes involved in the pipe, as well as the terminal process’ stdout. There are two implementations of Pipe._communicate, one for MS Windows, and one for POSIX systems. The MS Windows implementation is currently untested.

>>> p = Pipe([['find', '/etc/'], ['grep', '^/etc/ssh$']])
>>> p.stdout
'/etc/ssh\n'
>>> p.status
1
>>> p.statuses
[1, 0]
>>> p.stderrs 
[...find: ...: Permission denied..., '']
libbe.util.subproc.invoke(args, stdin=None, stdout=-1, stderr=-1, expect=(0, ), cwd=None, unicode_output=True, verbose=False, encoding=None)

expect should be a tuple of allowed exit codes. cwd should be the directory from which the command will be executed. When unicode_output == True, convert stdout and stdin strings to unicode before returing them.

Previous topic

libbe.util.plugin

Next topic

libbe.util.tree

This Page