user2125827 user2125827 - 5 months ago 22
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.."
else:
print "Condition fail.."


OUTPUT:-

Z:\loadbuild>python calculate_attempts.py
1

Condition fail..

Answer

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':
    ...
Comments