executable#

class Executable(name: str | Path)#

Bases: object

Create a callable object for the executable name

Parameters:

name – The path to an executable which is run when called. If name is not an absolute or relative path on the filesystem, the path to the executable is looked for on PATH.

Examples

>>> ls = Executable("ls")
>>> result = ls("-la", stdout=os.devnull)
>>> result.returncode
0
static find(name: str | Path) Path#

Find the path to the command name

property command: str#

The command-line string.

Returns:

The executable and default arguments

Return type:

str

property name: str#

The executable name.

Returns:

The basename of the executable

Return type:

str

property path: Path#

The path to the executable.

Returns:

The path to the executable

Return type:

str

add_default_args(*args: str) None#

Add flags to this executable’s default arguments

add_default_env(*args: dict[str, str], **kwargs: str) None#

Add variables to this executable’s runtime environment

Parameters:
  • args – A dictionary of environment variables

  • kwargs – Environment variables

is_executable(path: str | Path) bool#
class Result(cmd: str, returncode: int = -1, out: str | None = None, err: str | None = None)#

Bases: object

cmd: str#
returncode: int = -1#
out: str | None = None#
err: str | None = None#
property stdout: str | None#
property stderr: str | None#
get_output() str#
get_error() str#
exception ProcessError#

Bases: Exception

exception CommandTimedOutError#

Bases: Exception

exception FileNotExecutableError#

Bases: Exception