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:
Exception
Simple 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:
object
Describes 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)[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 (
Optional
[Path
]) – Path to execute in.stdout (
Union
[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 (
Union
[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 ifcommand
returns a non-zero return code.
- 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: