How to use the pexpect.fdpexpect.fdspawn function in pexpect

To help you get started, we’ve selected a few pexpect examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github labgrid-project / labgrid / labgrid / serial_expect.py View on Github external
def __init__(self):
        self.serial = serial.Serial(SERIAL_PORT, 115200)
        self.expect = fdpexpect.fdspawn(
            self.serial, logfile=open('expect.log', 'bw')
        )
        self.password = PASSWORD
        self.prompt = PROMPT
        self.logger = logging.getLogger('SerialExpect')
        self.login()
github intel / tcf / ttbd / ttbl / flasher.py View on Github external
self.pid_s = None
        tcp_port_base = -1
        try:
            try:
                self.pid_s = self.tt.fsdb.get("openocd.pid")
                if self.pid_s == None:
                    raise self.error("can't find OpenOCD's pid")
                self.pid = int(self.pid_s)
                tcp_port_base = int(self.tt.fsdb.get("openocd.port"))
                self.log.debug("connecting to openocd pid %d port %d"
                               % (self.pid, tcp_port_base + 1))
                self.sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                # TCL conection!
                self.sk.settimeout(5)
                self.sk.connect(("localhost", tcp_port_base + 1))
                self.p = pexpect.fdpexpect.fdspawn(
                    self.sk.fileno(),
                    # Open logfile with no codec anything, this seems to
                    # yield the best result to avoid UnicodeErrors; we
                    # open it, however, as utf-8,errors=replace
                    # Append to log file, so we can tell the full story
                    logfile = open(self.log_name + ".expect", "ab"),
                    timeout = 5)
                # FDexpect seems to have a bug where an EAGAIN is just
                # floated up instead of waiting
                self.p.read_nonblocking_original = self.p.read_nonblocking
                self.p.read_nonblocking = types.MethodType(
                    read_nonblocking_patched, self.p)
            except (Exception, OSError) as e:
                s = "expect init (pid %s port %d) failed: %s" \
                    % (self.pid_s, tcp_port_base + 1, e)
                if type(e) == Exception:	# Code BUG?