user2125827 user2125827 - 1 year ago 110
Android Question

integer comparision failure

Can anyone help to understand why the following integer comparison fails

import subprocess
cmd = "adb -s serialid shell getprop sys.boot"
proc = subprocess.Popen(cmd.split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
outs, errs = proc.communicate()
print outs
if outs ==1:
print "Condition met.."
print "Condition fail.."



Condition fail..

Answer Source

outs is the stuff that the process prints to standard output. As such, it will be a string, not an int. Since they are different types, the comparison will always fail.

Perhaps your condition should be something like:

if outs.strip() == '1':
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download