Class Process
source code
object --+
|
Process
A wrapper for subprocess.Popen that allows bash-like pipe syntax and
simplified output retrieval.
Processes will be executed automatically when and if stdout, stderr or
a return code are requested. This removes the necessity of calling
Popen().wait()
manually, or of capturing stdout and stderr
from a communicate()
call. A small change, to be sure, but
it helps reduce overhead for a common pattern.
One may use the |
operator to pipe the output of one Process into
another:
>>> p = Process("echo 'one two three'") | Process("wc -w")
>>> print p.stdout
3
void
|
__init__(self,
cmd,
stdin=None)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature |
source code
|
|
str
|
|
Process
|
__or__(self,
proc)
Override default or comparison so that the
| operator will work. |
source code
|
|
|
|
|
|
|
|
|
|
|
__del__(self)
Make dead sure the process has been cleaned up when garbage is
collected. |
source code
|
|
Inherited from object :
__delattr__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__setattr__
|
|
_stdin = -1
|
|
_stdout = -1
|
|
_stderr = -1
|
|
_retcode = None
|
bool
|
hasExecuted
A boolean indicating whether or not the process has already run.
|
str
|
stdout
Retrieve the contents of stdout, executing the process first if
necessary.
|
str
|
stderr
Retrieve the contents of stderr, executing the process first if
necessary.
|
int
|
retcode
Get the exit code of the executed process, executing the process
first if necessary.
|
int
|
pid
Get the pid of the executed process.
|
Inherited from object :
__class__
|
__init__(self,
cmd,
stdin=None)
(Constructor)
| source code
|
x.__init__(...) initializes x; see x.__class__.__doc__ for
signature
- Parameters:
cmd (str, list) - A string or list containing the command to be executed.
stdin (file) - An optional open file object representing input to the process.
- Returns: void
- Overrides:
object.__init__
|
Shortcut to get process output.
- Returns: str
- Process output
|
Override default or comparison so that the |
operator will work. Don't call this directly.
- Returns: Process
- Process with
self 's stdin as stdout pipe.
|
__str__(self)
(Informal representation operator)
| source code
|
str(x)
- Overrides:
object.__str__
- (inherited documentation)
|
repr(x)
- Overrides:
object.__repr__
- (inherited documentation)
|
hasExecuted
A boolean indicating whether or not the process has already run.
- Get Method:
- unreachable.hasExecuted(self)
- A boolean indicating whether or not the process has already run.
- Type:
- bool
|
stdout
Retrieve the contents of stdout, executing the process first if
necessary.
- Get Method:
- unreachable.stdout(self)
- Retrieve the contents of stdout, executing the process first if necessary.
- Type:
- str
|
stderr
Retrieve the contents of stderr, executing the process first if
necessary.
- Get Method:
- unreachable.stderr(self)
- Retrieve the contents of stderr, executing the process first if necessary.
- Type:
- str
|
retcode
Get the exit code of the executed process, executing the process first
if necessary.
- Get Method:
- unreachable.retcode(self)
- Get the exit code of the executed process, executing the process first if
necessary.
- Type:
- int
|
pid
Get the pid of the executed process.
- Get Method:
- unreachable.pid(self)
- Get the pid of the executed process.
- Type:
- int
|