-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathmyprocess.py
More file actions
33 lines (28 loc) · 863 Bytes
/
myprocess.py
File metadata and controls
33 lines (28 loc) · 863 Bytes
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
import logging
import subprocess
from pathlib import Path
from typing import Any, Optional, Union
from multiversx_sdk_cli import errors
logger = logging.getLogger("myprocess")
def run_process(
args: list[str],
env: Any = None,
dump_to_stdout: bool = True,
cwd: Optional[Union[str, Path]] = None,
) -> str:
logger.info(f"run_process: {args}, in folder: {cwd}")
try:
output = subprocess.check_output(
args,
shell=False,
universal_newlines=True,
stderr=subprocess.STDOUT,
env=env,
cwd=cwd,
)
logger.info("Successful run. Output:")
if dump_to_stdout:
print(output or "[No output]")
return output
except subprocess.CalledProcessError as error:
raise errors.ExternalProcessError(error.cmd, error.output)