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¶
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.
This method will remove stdout and stderr file upon reading both streams
- class buildtest.utils.command.BuildTestCommand(cmd)¶
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.
cmd (str) – Input shell command
Execute a system command and return output and error.
Returns the return code from shell command
returncode of shell command
- Return type
Given a line of output (error or regular) decode using the system default, if appropriate
Returns the output content from shell command
Returns the error content from shell command
Returns the executed command