
http://pypi.python.org/pypi/streamexpect/
import serial
import streamexpect
# timeout=0 is essential, as streams are required to be non-blocking
ser = serial.Serial('COM1', baudrate=115200, timeout=0)
with streamexpect.wrap(ser) as stream:
stream.write('\r\nuname -a\r\n')
match = stream.expect_bytes('Linux', timeout=1.0)
print(u'Found Linux at index {}'.format(match.start))