Class method to invoke shell commands and retrieve output and error.
capture output from stdout and stderr into capture object.
- class buildtest.utils.command.BuildTestCommand(cmd=None)¶
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
- decode(self, line)¶
Given a line of output (error or regular) decode using the system default, if appropriate
Execute a system command and return output and error. :param cmd: shell command to execute :type cmd: str, required :return: Output and Error from shell command :rtype: two str objects
Returns the executed command :rtype: str
Returns the error from shell command :rtype: str
Returns the output from shell command :rtype: str
Returns the return code from shell command :rtype: int
- set_command(self, cmd)¶
parse is called when a new command is provided to ensure we have a list. We don’t check that the executable is on the path, as the initialization might not occur in the runtime environment.
- 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:
And cleanup means deleting these files, if they exist.
- __exit__(self, *args)¶
- property err(self)¶
Return error stream. Returns empty string if empty or doesn’t exist. Returns (str) : error stream written to file
- property out(self)¶
Return output stream. Returns empty string if empty or doesn’t exist. Returns (str) : output stream written to file