blob: 09e84b21b06dc2d9b717f4bf08c34cf70eee56d1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
import subprocess
import logging
from typing import List, Optional
def run_shell_command(cmd: List[str], logger: logging.Logger) -> Optional[str]:
logger.debug(f"running command: {cmd}")
try:
return subprocess.run(
cmd, capture_output=True, text=True, check=True
).stdout.strip()
except FileNotFoundError as e:
logger.error(f"excecutable not found: {cmd[0]}, {e}")
return None
except subprocess.CalledProcessError as e:
logger.error(f"command failed: {cmd}, {e.stderr}")
return None
|