2024-03-20 03:39:09 +08:00
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
2024-03-22 03:58:16 +08:00
|
|
|
def run_cmd(cmd: list[str], cwd=None, env=None) -> str:
|
|
|
|
return subprocess.check_output(cmd, encoding='utf8', cwd=cwd, env=env).strip()
|
2024-03-20 03:39:09 +08:00
|
|
|
|
|
|
|
|
2024-03-22 03:58:16 +08:00
|
|
|
def run_cmd_default(cmd: list[str], default: str = "", cwd=None, env=None) -> str:
|
2024-03-20 03:39:09 +08:00
|
|
|
try:
|
2024-03-22 03:58:16 +08:00
|
|
|
return run_cmd(cmd, cwd=cwd, env=env)
|
2024-03-20 03:39:09 +08:00
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
return default
|
|
|
|
|