alt-ostree/alt/common/tools.py
2024-11-18 17:40:01 +03:00

28 lines
643 B
Python

import subprocess
from loguru import logger
def run_cmd(cmd: str) -> subprocess.Popen:
return subprocess.Popen(
args=cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
def run_cmd_log(cmd: str) -> subprocess.Popen:
with run_cmd(cmd) as proc:
if proc.stdout is not None:
stdout_data = proc.stdout.read().decode()
if stdout_data:
logger.info(stdout_data)
if proc.stderr is not None:
stderr_data = proc.stderr.read().decode()
if stderr_data:
logger.info(stderr_data)
return proc