forked from vkethana/r2e-docker-setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbash_utils.py
43 lines (41 loc) · 1.2 KB
/
bash_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import subprocess
from logging import Logger
from subprocess import CompletedProcess
def run_subprocess_shell(
command: str, repo_logger: Logger | None = None, **kwargs
) -> CompletedProcess[str]:
try:
result = subprocess.run(
command,
executable="/bin/bash",
shell=True,
capture_output=True,
text=True,
# check=True,
**kwargs,
)
except subprocess.TimeoutExpired as e:
if repo_logger:
repo_logger.error(f"Timeout expired for {command}")
result = CompletedProcess(
args=command,
returncode=1,
stderr="Timeout expired",
)
except subprocess.CalledProcessError as e:
if repo_logger:
repo_logger.error(f"CalledProcessError running {command} -- {e}")
result = CompletedProcess(
args=command,
returncode=1,
)
except Exception as e:
if repo_logger:
repo_logger.error(f"Error running {command} -- {e}")
result = CompletedProcess(
args=command,
returncode=1,
stdout="",
stderr=str(e),
)
return result