mscp.common_utils.run_command
Logged subprocess wrapper used across mSCP.
run_command runs a shell command via subprocess.run after splitting
it with shlex.split, logs the invocation, and returns
(stdout, error) tuples so callers don’t have to manage exceptions.
Functions
Section titled “Functions”run_command
Section titled “run_command”run_command(command: str, capture_output: bool=True, text: bool=True, check: bool=True) -> tuple[str | None, str | None]Run a shell command and return (stdout, error).
The command string is split with shlex.split (so simple quoting
works but shell features like pipes do not). All exceptions from
subprocess.run are caught and surfaced via the second tuple
element instead of being raised.
Args
command(str) — Shell command to execute.capture_output(bool) — Forwarded tosubprocess.run. When false, stdout / stderr go to the parent’s streams. Defaults toTrue.text(bool) — Forwarded tosubprocess.run; when false the return tuple’s first element is alwaysNone. Defaults toTrue.check(bool) — Forwarded tosubprocess.run. When true (default), non-zero exits become aCalledProcessErrorthat this function turns into a non-Nonesecond tuple element.
Returns
- tuple[str | None, str | None]:
(stdout, None)on success,(None, error_message)on failure. Withtext=Falsethe successful tuple is(None, None).