I am trying to use pexpect on serial port. I use fdpexpect as suggested. But I noticed that expect() does not obey timeout. Instead, the EOF happens.
ser = serial.Serial(sys.argv[1], 9600)
fd = fdpexpect.fdspawn(ser.fd)
fd.send('%s\r' % username)
i = fd.expect(['Password:', pexpect.TIMEOUT], timeout=30)
if i == 0:
fd.send('%s\r' % password)
else:
print 'Boom!'
It seems that instead of catching either, pexpect.exceptions.EOF is raised almost immediately. If I add pexpect.EOF to the list of match, EOF will be matched immediately. Granted, it is a serial port and data most likely has not arrived yet. If I add time.sleep(1) before fd.expect(), it will work. But that defeats the purpose of expect. Am I doing something wrong?