File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,14 @@ class Command(NamedTuple):
1212 return_code : int
1313
1414
15+ def _try_decode (bytes_ : bytes ) -> str :
16+ try :
17+ return bytes_ .decode ("utf-8" )
18+ except UnicodeDecodeError :
19+ result = chardet .detect (bytes_ )
20+ return bytes_ .decode (result ["encoding" ] or "utf-8" )
21+
22+
1523def run (cmd : str ) -> Command :
1624 process = subprocess .Popen (
1725 cmd ,
@@ -23,8 +31,8 @@ def run(cmd: str) -> Command:
2331 stdout , stderr = process .communicate ()
2432 return_code = process .returncode
2533 return Command (
26- stdout . decode ( chardet . detect ( stdout )[ "encoding" ] or "utf-8" ),
27- stderr . decode ( chardet . detect ( stderr )[ "encoding" ] or "utf-8" ),
34+ _try_decode ( stdout ),
35+ _try_decode ( stderr ),
2836 stdout ,
2937 stderr ,
3038 return_code ,
You can’t perform that action at this time.
0 commit comments