buildtest.utils.command
Module Contents
Classes
capture output from stdout and stderr into capture object. |
|
Class method to invoke shell commands and retrieve output and error. |
- class buildtest.utils.command.Capturing[source]
capture output from stdout and stderr into capture object. This is based off of github.com/vsoch/gridtest but modified to write files. The stderr and stdout are set to temporary files at the init of the capture, and then they are closed when we exit. This means expected usage looks like:
with Capturing() as capture: process = subprocess.Popen(...)
And then the output and error are retrieved from reading the files: and exposed as properties to the client: capture.out, capture.err
And cleanup means deleting these files, if they exist.
- property out
Return content of output stream if file exists otherwise returns empty string
- property err
Return content of error stream if file exists otherwise returns empty string.
- class buildtest.utils.command.BuildTestCommand(cmd)[source]
Class method to invoke shell commands and retrieve output and error. This class is inspired and derived from utils functions in https://github.com/vsoch/scif
The initializer method will initialize class variables and check input argument cmd and make sure command is in a list format.
- Parameters:
cmd (str) – Input shell command
- execute(timeout=None)[source]
Execute a system command and return output and error.
- Parameters:
timeout (int, optional) – The timeout value in number of seconds for a process. This argument is passed to Popen.communicate
- returncode()[source]
Returns the return code from shell command
- Returns:
returncode of shell command
- Return type: