Print Result subprocess.call

I am trying to return the temperature of my disk on a single line using the "Temp:" parameter as a prefix. To do this, I run a simple script to concatenate the string with the output of the command.

import subprocess

command = "sudo smartctl -A /dev/sda | egrep Temperature_Celsius | awk '{print $10}'"

print "Temp " + str(subprocess.call(command, shell=True))


Result:

29
Temp 0


When I delete the line "print", "29" is also not displayed. Therefore, when I use the print operator, the script for some reason returns “29” (?!), And then returns 0 from blue, and 29 is the correct value.

I would like to get this:

Temp: 29

os.system . "command = str (subprocess.call(", . os.system subprocess.call, . Googled AWK, , - , .

Python 2.7 Linux 3.8.0-34-generi# 49-Ubuntu SMP 12 18:00:10 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

+4
1

subprocess.call() ( 0 ). , subprocess.check_output():

print "Temp " + subprocess.check_output(command, shell=True)
+7

Source: https://habr.com/ru/post/1529458/


All Articles