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) · 673 Bytes
/
Copy pathcmd.py
File metadata and controls
31 lines (26 loc) · 673 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
import chardet
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(
stdout.decode(chardet.detect(stdout)["encoding"] or "utf-8"),
stderr.decode(chardet.detect(stderr)["encoding"] or "utf-8"),
stdout,
stderr,
return_code,
)