Skip to main content
added 10 characters in body
Source Link
Alex P.
  • 32k
  • 17
  • 124
  • 178

TheIn Python3 the subprocess.check_output() is usedreturns bytes which need to check if a system command executed sucessfully or not. To get the exact output ofbe decoded to the command, you shouldstring before string functions could be used. Another option is to use the legacy subprocess.getoutput() methodfunction.

The following code does the job for me:

items = [s.split('\t: ') for s in subprocess.getoutput(["cat /proc/cpuinfo | grep 'model name\|Hardware\|Serial' | uniq "]).splitlines()] 

Thanks @AlexP.

The subprocess.check_output() is used to check if a system command executed sucessfully or not. To get the exact output of the command, you should use subprocess.getoutput() method.

The following code does the job for me:

items = [s.split('\t: ') for s in subprocess.getoutput(["cat /proc/cpuinfo | grep 'model name\|Hardware\|Serial' | uniq "]).splitlines()] 

Thanks @AlexP.

In Python3 the subprocess.check_output() returns bytes which need to be decoded to the string before string functions could be used. Another option is to use the legacy subprocess.getoutput() function.

The following code does the job for me:

items = [s.split('\t: ') for s in subprocess.getoutput(["cat /proc/cpuinfo | grep 'model name\|Hardware\|Serial' | uniq "]).splitlines()] 
Source Link

The subprocess.check_output() is used to check if a system command executed sucessfully or not. To get the exact output of the command, you should use subprocess.getoutput() method.

The following code does the job for me:

items = [s.split('\t: ') for s in subprocess.getoutput(["cat /proc/cpuinfo | grep 'model name\|Hardware\|Serial' | uniq "]).splitlines()] 

Thanks @AlexP.