craft_parts.utils.process module¶
Utilities for executing subprocesses and handling their stdout and stderr streams.
- exception craft_parts.utils.process.ProcessError(result)[source]¶
Bases:
ExceptionSimple error for failed processes.
Generally raised if the return code of a process is non-zero.
- Parameters:
result (
ProcessResult)
-
result:
ProcessResult¶
- class craft_parts.utils.process.ProcessResult(returncode, stdout, stderr, combined, command)[source]¶
Bases:
objectDescribes the outcome of a process.
- Parameters:
returncode (
int)stdout (
bytes)stderr (
bytes)combined (
bytes)command (
str|Path|Sequence[str|Path])
-
combined:
bytes¶
-
command:
str|Path|Sequence[str|Path]¶
-
returncode:
int¶
-
stderr:
bytes¶
-
stdout:
bytes¶
- craft_parts.utils.process.run(command, *, cwd=None, stdout=None, stderr=None, check=True, selector=None)[source]¶
Execute a subprocess and collect its output.
This function collects the stdout and stderr streams as separate accounts and a singular, combined account.
- Parameters:
command (
str|Path|Sequence[str|Path]) – Command to execute.cwd (
Path|None) – Path to execute in.stdout (
TextIO|int|None) – Handle to a fd or I/O stream to treat as stdout. None defaults tosys.stdout, and process.DEVNULL can be passed for no printing or stream capturing.stderr (
TextIO|int|None) – Handle to a fd or I/O stream to treat as stderr. None defaults tosys.stderr, and process.DEVNULL can be passed for no printing or stream capturing.check (
bool) – If True, a ProcessError exception will be raised ifcommandreturns a non-zero return code.selector (
BaseSelector|None) – If defined, use the caller-supplied selector instead of creating a new one.
- Raises:
ProcessError – If process exits with a non-zero return code.
OSError – If the specified executable is not found.
- Returns:
A description of the process’ outcome.
- Return type: