forked from commitizen-tools/commitizen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd.py
More file actions
31 lines (26 loc) · 640 Bytes
/
Copy pathcmd.py
File metadata and controls
31 lines (26 loc) · 640 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
import subprocess
from typing import NamedTuple
from charset_normalizer import from_bytes
class Command(NamedTuple):
out: str
err: str
stdout: bytes
stderr: bytes
return_code: int
def run(cmd: str) -> Command:
process = subprocess.Popen(
cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE,
)
stdout, stderr = process.communicate()
return_code = process.returncode
return Command(
str(from_bytes(stdout).best()),
str(from_bytes(stderr).best()),
stdout,
stderr,
return_code,
)