Wednesday, 14 August 2013

Check output of a python command

Check output of a python command

I have a python script which tries to run an external command and look for
result of the command. And it needs to use the value 'count=' from the
output of the external command
COUNT_EXP = re.compile("count=(.*)")
cmd = [] # external command
p = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
for line in iter(p.stdout.readline, b''):
result = COUNT_EXP.match(line)
if result:
print "count= " + result.group(1)
return int(result.group(1))
When I try to run my script, my external command ("cmd") got execute and I
see count=10 in the shell. But why my python can't find that and print out
"count= 10? in the 'if' clause above?

No comments:

Post a Comment