Execute a command via subprocess.Popen and returns the stdio. :param string|list cmd: A list or string representing the command to run. :param string stdin_payload: A string representing the stdin payload, if any, to send. :param **kwargs: Additional kwargs to pass through t
(cls, cmd, stdin_payload=None, **kwargs)
| 78 | |
| 79 | @classmethod |
| 80 | def execute(cls, cmd, stdin_payload=None, **kwargs): |
| 81 | """Execute a command via subprocess.Popen and returns the stdio. |
| 82 | |
| 83 | :param string|list cmd: A list or string representing the command to run. |
| 84 | :param string stdin_payload: A string representing the stdin payload, if any, to send. |
| 85 | :param **kwargs: Additional kwargs to pass through to subprocess.Popen. |
| 86 | :return: A tuple of strings representing (stdout, stderr), pre-decoded for utf-8. |
| 87 | :raises: `Executor.ExecutableNotFound` when the executable requested to run does not exist. |
| 88 | `Executor.NonZeroExit` when the execution fails with a non-zero exit code. |
| 89 | """ |
| 90 | process = cls.open_process( |
| 91 | cmd=cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs |
| 92 | ) |
| 93 | stdout_raw, stderr_raw = process.communicate(input=stdin_payload) |
| 94 | # N.B. In cases where `stdout` or `stderr` is passed as parameters, these can be None. |
| 95 | stdout = stdout_raw.decode("utf-8") if stdout_raw is not None else stdout_raw |
| 96 | stderr = stderr_raw.decode("utf-8") if stderr_raw is not None else stderr_raw |
| 97 | |
| 98 | if process.returncode != 0: |
| 99 | raise cls.NonZeroExit(cmd, process.returncode, stdout, stderr) |
| 100 | |
| 101 | return stdout, stderr |
nothing calls this directly
no test coverage detected