add possibility to specify subprocess stdout encoding
authorSurkov Sergey <surkovsv93@gmail.com>
Mon, 04 Dec 2017 19:35:31 +0300
changeset 1883 20ec80d6fd70
parent 1882 3707240447f8
child 1884 48bd91d7a0ae
add possibility to specify subprocess stdout encoding
util/ProcessLogger.py
--- a/util/ProcessLogger.py	Mon Dec 04 11:20:46 2017 +0300
+++ b/util/ProcessLogger.py	Mon Dec 04 19:35:31 2017 +0300
@@ -78,7 +78,7 @@
                  no_stdout=False, no_stderr=False, no_gui=True,
                  timeout=None, outlimit=None, errlimit=None,
                  endlog=None, keyword=None, kill_it=False, cwd=None,
-                 encoding=None):
+                 encoding=None, output_encoding=None):
         self.logger = logger
         if not isinstance(Command, list):
             self.Command_str = Command
@@ -95,6 +95,7 @@
             self.Command_str = subprocess.list2cmdline(self.Command)
 
         fsencoding = sys.getfilesystemencoding()
+        self.output_encoding = output_encoding
 
         if encoding is None:
             encoding = fsencoding
@@ -155,6 +156,8 @@
         self.startsem.release()
 
     def output(self, v):
+        if v and self.output_encoding:
+            v = v.decode(self.output_encoding)
         self.outdata.append(v)
         self.outlen += 1
         if not self.no_stdout:
@@ -163,6 +166,8 @@
             self.endlog()
 
     def errors(self, v):
+        if v and self.output_encoding:
+            v = v.decode(self.output_encoding)
         self.errdata.append(v)
         self.errlen += 1
         if not self.no_stderr: