Add helper exec_cmd

main
Felix Stupp 2 years ago
parent 79fca1994c
commit 51982682c6
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -25,10 +25,11 @@
from __future__ import annotations
import argparse
from functools import cached_property, wraps
from functools import cache, cached_property, wraps
import os
from pathlib import Path
import shlex
from subprocess import CompletedProcess, PIPE, run
import sys
from typing import (
Dict,
@ -131,6 +132,18 @@ def combine_cmds(*commands: CommandArgs | List[Optional[str]]) -> CommandArgs:
return CommandArgs([arg for cmd in commands for arg in filter_cmds(cmd)])
def exec_cmd(
command: CommandArgs, check: bool = True, capture_stdout: bool = True
) -> CompletedProcess:
res = run(
args=command,
check=check,
shell=False,
stdout=PIPE if capture_stdout else None,
)
return res
@wraps(print)
def error(*args, **kwargs):
ret = print(*args, file=sys.stderr, **kwargs)

Loading…
Cancel
Save