I am trying to read the output of pexpect.send(cmd) but here's the problem I am facing.
I am sending many commands in a sequence and I want to read/expect after a certain set of commands. Condition is that only the output of last command is to be considered. But
There are three ways in which this problem can be handled but none to flush the buffer
sendcall should be matched with a call to
expect. This ensures that the file pointer has moved ahead of the previous send.
sendbefore a single
expectthen we need to provide a way to move file pointer to the location of last send. This can be done by an extra
expectoutput is unique. The uniqueness should be such that none of the
sendin the series of
sendshould give that output.
logfile_readto a file. All the output will be logged to this file. Before the
sendfor which the
expectis used, get the position of file pointer. Now get the position of file pointer after the send as well. Search for expected pattern in the file in between first and second pointer.
First method is the ideal way it should be done.