Exec

This module provides helpers to run subprocesses.

It handles subprocesses stderr and stdout in a way that doesn’t break loggers from yuio.io.

yuio.exec.exec(*args: str, cwd: Union[None, str, Path] = 'None', env: Optional[Dict[str, str]] = 'None', input: Optional[str] = 'None', level: int = 'yuio.io.INFO') str[source]
yuio.exec.exec(*args: str, cwd: Union[None, str, Path] = 'None', env: Optional[Dict[str, str]] = 'None', input: Union[None, str, bytes] = 'None', level: int = 'yuio.io.INFO', text: bool = 'True') Union[str, bytes]

Run an executable and return its stdout.

Command’s stderr is interactively printed to the log.

If the command fails, a CalledProcessError is raised.

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.

  • level – logging level for stderr outputs.

  • text – if true (default), decode stdout the system default encoding.

Returns

string (or bytes) with command’s stdout.

yuio.exec.sh(cmd: str, shell: str = '/bin/sh', *, cwd: Union[None, str, Path] = 'None', env: Optional[Dict[str, str]] = 'None', input: Optional[str] = 'None', level: int = 'yuio.io.INFO') str[source]
yuio.exec.sh(cmd: str, shell: str = '/bin/sh', *, cwd: Union[None, str, Path] = 'None', env: Optional[Dict[str, str]] = 'None', input: Union[str, bytes] = 'None', level: int = 'yuio.io.INFO', text: bool = 'True') Union[str, bytes]

Run command in a shell, returns its stdout.

Parameters
  • cmd – shell command.

  • shell – which shell to use. Default is /bin/sh.

  • cwd – set the current directory before the command is executed.

  • env – define the environment variables for the command.

  • input – string with command’s stdin.

  • level – logging level for stderr outputs.

  • text – if true (default), decode stdout the system default encoding.

Returns

string (or bytes) with command’s stdout.