X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=src%2Fpyutils%2Fexec_utils.py;h=c235171c5d33f9afaa97e8840f9917b5d009857f;hb=HEAD;hp=6fcd340a05b301680cfdf696a2f1a178355aea9f;hpb=ce6215906307baf0dca28f46444001389abd584e;p=pyutils.git diff --git a/src/pyutils/exec_utils.py b/src/pyutils/exec_utils.py index 6fcd340..c235171 100644 --- a/src/pyutils/exec_utils.py +++ b/src/pyutils/exec_utils.py @@ -126,7 +126,6 @@ def cmd_exitcode(command: str, timeout_seconds: Optional[float] = None) -> int: def cmd(command: str, timeout_seconds: Optional[float] = None) -> str: """Run a command and capture its output to stdout and stderr into a string buffer. Return that string as this function's output. - Raises subprocess.CalledProcessError or TimeoutExpired on error. Args: command: the command to run @@ -136,6 +135,10 @@ def cmd(command: str, timeout_seconds: Optional[float] = None) -> str: Returns: The captured output of the subprocess' stdout as a string buffer + Raises: + CalledProcessError: the child process didn't exit cleanly + TimeoutExpired: the child process ran too long + >>> cmd('/bin/echo foo')[:-1] 'foo' @@ -234,7 +237,11 @@ def cmd_in_background(command: str, *, silent: bool = False) -> subprocess.Popen def cmd_list(command: List[str]) -> str: """Run a command with args encapsulated in a list and return the - output text as a string. Raises subprocess.CalledProcessError. + output text as a string. + + Raises: + CalledProcessError: the child process didn't exit cleanly + TimeoutExpired: the child process ran too long """ ret = subprocess.run(command, capture_output=True, check=True).stdout return ret.decode("utf-8")