Python Forum

Full Version: question on syntax
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

the code below should return UP but it returns DOWN and I cannot understand why.
any help is appreciated.
TIA

from __future__ import print_function
import subprocess

_cmd = 'grep RUNNING /proc/asound/card*/pcm*/sub*/status'
cmd = 'cat /proc/asound/card*/pcm*/sub*/status | grep state:'

p = subprocess.check_output(cmd,shell=True).decode("utf-8")
print(p)
#prints state: RUNNING

if (p=='state: RUNNING'):
  print('UP')
else:
  print('DOWN')

Nevermind. I had white spaces in line.
p may have a line feed, try if p.strip() == 'state: RUNNING':