Skip to content

Process

The rite.system.process submodule wraps subprocess and related functionality for running and managing external commands.

Process Module

Process and subprocess management.

This submodule provides utilities for executing system commands and managing subprocess operations.

Examples

from rite.system.process import process_run code, out, err = process_run(["ls"], Path.cwd())

Modules

process_call

Process Call

Execute command and wait for completion.

Examples

from rite.system.process import process_call exit_code = process_call(["ls", "-la"])

Functions

process_call(cmd: list[str], cwd: Path | str | None = None) -> int

Execute command and return exit code.

Parameters:

Name Type Description Default
cmd list[str]

Command as list of strings.

required
cwd Path | str | None

Working directory. Defaults to current.

None

Returns:

Type Description
int

Command exit code.

Examples:

>>> process_call(["echo", "hello"])
0
>>> process_call(["false"])
1
Notes

Does not capture output. Output goes to terminal.

process_check_output

Process Check Output

Execute command and return output.

Examples

from rite.system.process import process_check_output output = process_check_output(["echo", "hello"])

Functions

process_check_output(cmd: list[str], cwd: Path | str | None = None) -> str

Execute command and return stdout.

Parameters:

Name Type Description Default
cmd list[str]

Command as list of strings.

required
cwd Path | str | None

Working directory. Defaults to current.

None

Returns:

Type Description
str

Command stdout as string.

Raises:

Type Description
CalledProcessError

If command fails.

Examples:

>>> process_check_output(["echo", "hello"])
'hello'
Notes

Raises exception on non-zero exit. Uses check_output for subprocess execution.

process_run

Process Run Command

Execute command in subprocess.

Examples

from rite.system.process import process_run code, out, err = process_run(["ls", "-la"], Path.cwd())

Functions

process_run(cmd: list[str], cwd: Path | str | None = None, check: bool = False, *, timeout: float | None = None, env: dict[str, str] | None = None, stdin_text: str | None = None) -> tuple[int, str, str]

Run command in subprocess and return result.

Parameters:

Name Type Description Default
cmd list[str]

Command as list of strings.

required
cwd Path | str | None

Working directory. Defaults to current.

None
check bool

Raise exception on non-zero exit.

False
timeout float | None

Timeout in seconds. None means no timeout.

None
env dict[str, str] | None

Environment variables for the process.

None
stdin_text str | None

Text to send to stdin.

None

Returns:

Type Description
tuple[int, str, str]

Tuple of (return_code, stdout, stderr).

Raises:

Type Description
CalledProcessError

If check=True and command fails.

TimeoutExpired

If timeout is exceeded.

Examples:

>>> process_run(["echo", "hello"])
(0, 'hello', '')
>>> process_run(["ls"], Path("/tmp"))
(0, '...', '')
>>> process_run(["cat"], stdin_text="hello")
(0, 'hello', '')
Notes

Uses subprocess.run for execution. Output is text mode with UTF-8 encoding.

options: show_root_heading: true show_source: false heading_level: 2