Utilities to run subprocesses
Run the command string cmdstr in a bash shell. It can have multiple lines. Each line is separately sent to the shell. The exit status is checked if the shell comes back with a PS1 prompt. Bash control structures like if or for use prompt PS2 and in this case status is not checked. At the end the printenv command may be used in order to find any changes to the environment that occurred as a result of the commands. If exit status is non-zero at any point then processing is terminated and a ShellError exception is raise.
| Parameters: |
|
|---|---|
| Returns: | (outlines, deltaenv) |
Render the input cmdstr and run in a bash shell. Output is logged at the VERBOSE level.
| Parameters: |
|
|---|---|
| Returns: | bash output string |
Run the cmdstr string in a bash shell and return the resulting update to the current python environment (os.environ).
| Parameters: |
|
|---|---|
| Returns: | Dict of environment vars update produced by cmdstr |
Run cmdstr in a bash shell and import the environment updates into the current python environment (os.environ).
| Parameters: |
|
|---|---|
| Returns: | Dict of environment vars update produced by cmdstr |
Bases: object
Example usage:
>>> from pyyaks.shell import Spawn, bash, getenv, importenv
>>>
>>> spawn = Spawn()
>>> status = spawn.run(['echo', 'hello'])
hello
>>> status
0
>>>
>>> try:
... spawn.run(['bad', 'command'])
... except Exception, error:
... error
...
OSError(2, 'No such file or directory')
>>> spawn.run(['bad', 'command'], catch=True)
Warning - OSError: [Errno 2] No such file or directory
>>> print spawn.exitstatus
None
>>> print spawn.outlines
['Warning - OSError: [Errno 2] No such file or directory\n']
>>>
>>> spawn = Spawn(stdout=None, shell=True)
>>> spawn.run('echo hello')
0
>>> spawn.run('fail fail fail')
127
>>>
>>> spawn = Spawn(stdout=None, shell=True, stderr=None)
>>> spawn.run('fail fail fail')
127
>>> print spawn.outlines
[]
to filenames supplied in outputs list
Run the command cmd and abort if timeout is exceeded.
| Parameters: |
|
|---|---|
| Return type: | process exit value |