Exec¶
This module provides helpers to run subprocesses and get their output.
It handles subprocess’ stderr and stdout in a way that doesn’t break
loggers from yuio.io.
- yuio.exec.exec(
- *args: str | Path,
- cwd: None | str | Path = None,
- env: dict[str, str] | None = None,
- capture_io: bool = True,
- input: None | str | bytes = None,
- logger: Logger | LoggerAdapter[Any] | str | None = None,
- level: int | None = None,
- text: bool = True,
Run an executable and return its stdout.
Command’s stderr is interactively printed to the log.
- Parameters:
args – command arguments.
cwd – set the current directory before the command is executed.
env – define the environment variables for the command.
input – string with command’s stdin. If text is set to
False, this should bebytes, otherwise it should be astr.capture_io – if set to
False, process’ stdout and stderr are not captured; logger and level arguments can’t be given in this case, and this function returnsNoneinstead of process’ output.logger – logger that will be used for logging command’s output. Default is to log to
yuio.exec.level – logging level for stderr outputs. Default is
logging.DEBUG.
- Returns:
string (or bytes) with command’s stdout, or
Noneif capture_io isFalse.- Raises:
If the command fails, a
CalledProcessErroris raised. If command can’t be started, raisesOSError.