pexpect看不到字符串

时间:2014-02-28 16:42:46

标签: string pexpect

我正在使用pexpect来比较衍生程序的输出。它会看到我想要的一切,直到达到某一点。这就是我要找的东西:

DeviceId 12001055
Waiting to check firmware info..............................
MsgName: Get Firmware Info
DeviceId 12001055
replyList name =  rfm_3.3.0+.bin
name.lower()=  rfm.bin
Elapsed time 173 secs
[12001055] RFU Result: False

它看到'DeviceId 12001055'和'等待检查固件信息',但之后它什么也看不到。我用这些字符串称之为期待:

"%s.+?\r" % 'Waiting to check firmware info'
"replyList name =  rfm_3.3.0+.bin.+?\r"

有什么想法吗?

代码:

def rfu(self, fileName = ''):
    line = CMD_RFU+' '+fileName
    print 'rfu %s' % line
    if self.serial:
        self.serial.wakeUp()
    self.p.sendline(line)
    basename = os.path.basename(fileName)
    basename = basename.lower()
    while True:
        ret = self._confirmFoundPattern("%s.+?\r" % 'Waiting to check firmware info',240)
        break # for whatever reason it doesn't see any strings after the Waiting for...
    cfp = "replyList name = rfm_3.3.0+.bin.+?\r"
    while True:
        ret = self._confirmFoundPattern(cfp)

def _confirmFoundPattern(self, search, timeout=PEXPECT_TIME_OUT):
    ''' Searches output for a particular string. Hoping it was found '''
    # print '_confirmFoundPattern \'%s\' to: %d\n' % (search, timeout)
    if search.endswith("DONT CARE"):
    return
    try:
        self.p.expect(search,timeout)
        #self.logToConsole("Matched String: {}".format(self.p.after))
        print self.p.after
        return self.p.after

0 个答案:

没有答案