[py] use universal_newlines=True to prevent decoding errors (see gh-247 gh-248)
authorPaul Brossier <piem@piem.org>
Mon, 6 May 2019 20:36:51 +0000 (22:36 +0200)
committerPaul Brossier <piem@piem.org>
Mon, 6 May 2019 20:36:51 +0000 (22:36 +0200)
python/lib/gen_external.py

index 1425c9b..e5f0a02 100644 (file)
@@ -120,23 +120,24 @@ def get_cpp_output(header=header, usedouble=False):
     print("Running command: {:s}".format(" ".join(cpp_cmd)))
     proc = subprocess.Popen(cpp_cmd,
                             stderr=subprocess.PIPE,
     print("Running command: {:s}".format(" ".join(cpp_cmd)))
     proc = subprocess.Popen(cpp_cmd,
                             stderr=subprocess.PIPE,
-                            stdout=subprocess.PIPE)
+                            stdout=subprocess.PIPE,
+                            universal_newlines=True)
     assert proc, 'Proc was none'
     cpp_output = proc.stdout.read()
     err_output = proc.stderr.read()
     if err_output:
         print("Warning: preprocessor produced errors or warnings:\n%s" \
     assert proc, 'Proc was none'
     cpp_output = proc.stdout.read()
     err_output = proc.stderr.read()
     if err_output:
         print("Warning: preprocessor produced errors or warnings:\n%s" \
-                % err_output.decode('utf8'))
+                % err_output)
     if not cpp_output:
         raise_msg = "preprocessor output is empty! Running command " \
                 + "\"%s\" failed" % " ".join(cpp_cmd)
         if err_output:
     if not cpp_output:
         raise_msg = "preprocessor output is empty! Running command " \
                 + "\"%s\" failed" % " ".join(cpp_cmd)
         if err_output:
-            raise_msg += " with stderr: \"%s\"" % err_output.decode('utf8')
+            raise_msg += " with stderr: \"%s\"" % err_output
         else:
             raise_msg += " with no stdout or stderr"
         raise Exception(raise_msg)
     if not isinstance(cpp_output, list):
         else:
             raise_msg += " with no stdout or stderr"
         raise Exception(raise_msg)
     if not isinstance(cpp_output, list):
-        cpp_output = [l.strip() for l in cpp_output.decode('utf8').split('\n')]
+        cpp_output = [l.strip() for l in cpp_output.split('\n')]
 
     return cpp_output
 
 
     return cpp_output