I have solved the problem.
Before:
cmd = "awk '{ arg=$2 } END {sub(/\.\..*$/,arg); print arg}' scan.txt"
x = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
AvgAPI.lastscanned = x.stdout.read()
Now:
Line_len = 1200
SEEK_END = 2
file = open('scan.txt', "r")
file.seek(-Line_len, SEEK_END)
data_scanfile_not_cleaned = str(file.read(Line_len)).split(" ")[1].strip()
if not data_scanfile_not_cleaned.startswith('/'):
file.close()
AvgAPI.lastscanned = ""
time.sleep(0.1)
else:
data_scanfile_re = re.sub(r'[~\s+(\d+)%]','',data_scanfile_not_cleaned)
data_scanfile_strip = data_scanfile_re.strip("[.]")
data_scanfile = data_scanfile_strip.strip("[K")
AvgAPI.lastscanned = data_scanfile
file.close()
time.sleep(0.1)
There are some minor flaws with the new solution, but it works satisfactorily.