gonets/SRV/core/cli_executor.py
2025-06-26 17:49:21 +05:00

27 lines
839 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import subprocess
from typing import Tuple
class CLIExecutor:
"""
Класс для выполнения CLI-команд
"""
@staticmethod
def run(command: list) -> Tuple[int, str]:
"""
Выполняет команду в системе и возвращает код и вывод.
Args:
command (list): Список аргументов команды для выполнения.
Returns:
tuple: Код возврата и вывод команды.
"""
result = subprocess.run(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=False, # Не вызываем исключение при ошибке
)
return result.returncode, result.stdout.decode("utf-8")