Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
question on syntax
#1
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.
Reply
#2
p may have a line feed, try if p.strip() == 'state: RUNNING':
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  syntax error question - string mgallotti 5 1,332 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  simple syntax question speedskis777 7 3,617 Mar-11-2019, 02:26 AM
Last Post: snippsat
  Question on a php syntax ebolisa 1 1,926 Jan-14-2019, 06:22 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020