I am making a script for a lab that will take an inventory of all servers there along with their stats. I use subprocess
to pass the output of bash commands into variables in my python code. However, the output I get back frustrates me. On one computer, the output of the following:
def codename():
"""
Determines the product name of the actual motherboard/machine that it is used on
:return: Returns the system's codename
"""
sysman = str(subprocess.check_output(('dmidecode', '-s', 'system-manufacturer'))).rstrip() + " "
sysprodname = str(subprocess.check_output(('dmidecode', '-s', 'system-product-name'))).rstrip() + " "
sysver = str(subprocess.check_output(('dmidecode', '-s', 'system-version'))).rstrip()
# Checks for incomplete information
sysinfo = [sysman, sysprodname, sysver]
for i in range(len(sysinfo)):
if not any(c.isalpha for c in sysinfo[i]):
sysinfo[i] = ""
sysname = sysman + sysprodname + sysver
if sysname is not None:
return str(sysname)
else:
return "---"
when called simply by calling codename()
in Python 2 (2.7 to be precise) will return:
innotek GmbH VirtualBox 1.2
while running it in Python 3 (3.6.5) returns:
b'innotek' GmbH\n' b'VirtualBox\n' b'1.2\n'
.
I am starting to think this is a python specific problem, but on another machine where I write the code (openSUSE Tumbleweed), python --version
returns:
Python 3.6.5
and python3 --version
also returns:
Python 3.6.5
.
However when I run it with python script.py
I get the well formatted string whereas when I run it with python3 script.py
, I get the string literal version. Can someone help me make some sense of this?