return bytes
return to_bytes(bytes)
+def convert_string(bytes):
+ try:
+ return to_string(bytes.decode('utf-8'))
+ except UnicodeError:
+ return str(bytes)
+
def detectCPUs():
"""
Detects the number of CPUs on a system. Cribbed from pp.
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env=env)
out,_ = p.communicate()
- return out
+ return convert_string(out)
def which(command, paths = None):
"""which(command, [paths]) - Look up the given command in the paths string
raise KeyboardInterrupt
# Ensure the resulting output is always of string type.
- try:
- out = to_string(out.decode('utf-8'))
- except:
- out = str(out)
- try:
- err = to_string(err.decode('utf-8'))
- except:
- err = str(err)
+ out = convert_string(out)
+ err = convert_string(err)
return out, err, exitCode