forked from starkware-libs/sequencer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
22 lines (21 loc) · 718 Bytes
/
Copy pathutils.py
File metadata and controls
22 lines (21 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import os
import subprocess
from typing import List
def run_command(command: str, allow_error: bool = False) -> List[str]:
"""
Runs a bash command and returns the output as a list of lines.
"""
try:
command_output = (
subprocess.check_output(command, shell=True, cwd=os.getcwd())
.decode("utf-8")
.splitlines()
)
output_lines = "\n".join(command_output)
print(f"Command '{command}' output:\n{output_lines}")
return command_output
except subprocess.CalledProcessError as error:
if not allow_error:
raise
print(f"Command '{command}' hit error: {error=}.")
return str(error).splitlines()