interact function

Command to allow interaction between two streams.

interact(stream1, stream2)

A stream can be any object accepted by socket.socket (a file descriptor or a file-like object), or a tuple containing two such objects. If a stream is a tuple, then the first item is the input stream (readable), the second is the output stream (writable). This allows uni-directional files to be used with interact.

Currently, this will direct all output from stream1 to the input of stream2 and the output of stream2 to the input of stream1. If any are None, then the data is ignored.

The function only returns on the exceptions ExpectPy.TimeoutError, EOFError and IOError.

interact method

This is a method of a spawned or unspawned object.


It calls the interact function above, passing the instance as the first argument. Meaning the above method call is equivalent to the function call: ExpectPy.interact(obj, stream2)


Connect a spawned object (to a telnet process) to the user.


Connect a spawned object to a pipe'd filter.

import os
filter_in = os.popen('pr -m -h "Data from process"', 'r')
# send data thru popen process
obj.interact((None, filter_in))