summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/util/executable.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/spack/spack/util/executable.py b/lib/spack/spack/util/executable.py
index 584e224db7..5fd40790ed 100644
--- a/lib/spack/spack/util/executable.py
+++ b/lib/spack/spack/util/executable.py
@@ -26,6 +26,7 @@ import os
import re
import subprocess
from six import string_types
+import sys
import llnl.util.tty as tty
import spack
@@ -184,9 +185,9 @@ class Executable(object):
if output is str or error is str:
result = ''
if output is str:
- result += out.decode('utf-8')
+ result += to_str(out)
if error is str:
- result += err.decode('utf-8')
+ result += to_str(err)
return result
except OSError as e:
@@ -223,6 +224,20 @@ class Executable(object):
return ' '.join(self.exe)
+def to_str(content):
+ """Produce a str type from the content of a process stream obtained with
+ Popen.communicate.
+ """
+ # Prior to python3, Popen.communicate returns a str type. For python3 it
+ # returns a bytes type. In the case of python3 we decode the
+ # byte string to produce a str type. This will generate junk if the
+ # encoding is not UTF-8 (which includes ASCII).
+ if sys.version_info < (3, 0, 0):
+ return content
+ else:
+ return content.decode('utf-8')
+
+
def which(*args, **kwargs):
"""Finds an executable in the path like command-line which.