common/run: add environment variable argument (#31957)

run add environment argument
old-commit-hash: efc32c2930
This commit is contained in:
Justin Newberry 2024-03-21 15:58:16 -04:00 committed by GitHub
parent ad3ae98a19
commit ac853fc354
1 changed files with 4 additions and 4 deletions

View File

@ -1,13 +1,13 @@
import subprocess
def run_cmd(cmd: list[str], cwd=None) -> str:
return subprocess.check_output(cmd, encoding='utf8', cwd=cwd).strip()
def run_cmd(cmd: list[str], cwd=None, env=None) -> str:
return subprocess.check_output(cmd, encoding='utf8', cwd=cwd, env=env).strip()
def run_cmd_default(cmd: list[str], default: str = "", cwd=None) -> str:
def run_cmd_default(cmd: list[str], default: str = "", cwd=None, env=None) -> str:
try:
return run_cmd(cmd, cwd=cwd)
return run_cmd(cmd, cwd=cwd, env=env)
except subprocess.CalledProcessError:
return default