python - String comparing between output system command with defined variable -


i tried compare output of command line variable that's defined logic throw false instead of true.

$ sudo hdparm -i /dev/sda | grep serial | awk '{print $3}' 6ra3x34p 

in python:

hdserial="6ra3x34p" cmd1="sudo hdparm -i /dev/sda | grep serial | awk '{print $3}'"  output = subprocess.check_output(cmd1, shell=true)  def check_serial(string):     if string != hdserial:         print '\nquitting..'         sys.exit()  check_serial(output) 

why comparison failing?

the output of command contains trailing newline. should remove using str.strip or str.rstrip:

output = subprocess.check_output(cmd1, shell=true).strip() 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -