pexpect: How to interact() over file object using newer version of pexpect library
<p><code>pexpect</code> has gone through big changes since the version provided by Ubuntu 15.04 (3.2). When installing newest version of <code>pexpect</code>  using <code>pip3</code>, this minimal program that previously successfully gave terminal emulation over serial console does not work any more:</p>

<pre><code>#!/usr/bin/python3

import serial
import pexpect.fdpexpect

ser = serial.Serial("/dev/ttyS0", baudrate=115200)
spawn = pexpect.fdpexpect.fdspawn(ser)
spawn.interact()
</code></pre>

<p>The newer API is missing interact() method in class <code>pexpect.fdpexpect.fdspawn</code> which used to be there.</p>

<p><strong>Question:</strong> how is the newer version of pexpect (currently 4.2.1) supposed to be used to provide free manual interaction with file object (serial port in this case)?</p>

<p><strong>Alternatively, question/work-around</strong>: I recognize I am using a bit heavy machinery for such a simple use case, any suggestions for other python libraries that can do the same as earlier version of pexpect could?</p>

<hr>

<p>Code reading: Examples use <code>pexpect.spawn(command_str)</code> to get a <code>spawn</code> object which has <code>interact()</code> method; actually this <code>pexpect.spawn()</code> is the same as directly creating a <code>pexpect.pty_spawn.spawn</code> object which has this method. On the other hand, <code>pexpect.fdpexpect.fdspawn()</code> will construct a <code>pexpect.fdpexpect.fdspawn</code> class which is missing <code>interact()</code> method. Both of these spawn classes derive from <code>pexpect.spawnbase.SpawnBase</code> class. Based on my quick reading, this looks like regression that resulted from refactoring on the way to version 4.x.</p>

<p>Browsing the <a href="https://github.com/pexpect/pexpect" rel="nofollow">pexpect</a> <a href="https://github.com/pexpect/pexpect/issues" rel="nofollow">issues</a>, found <a href="https://github.com/pexpect/pexpect/issues/351" rel="nofollow">#351</a>, <a href="https://github.com/pexpect/pexpect/issues/356" rel="nofollow">#356</a>, and the newly submitted <a href="https://github.com/pexpect/pexpect/issues/377" rel="nofollow">#377</a>. By my quick reading, it seems this is a regression that was brought by uncompleted refactoring along the way towards new major release version 4. There are three possible avenues:</p>

<ol>
<li><p>Make sure to install older version:</p>

<p>$ pip3 install "pexpect&lt;3"</p>

<p>(or make sure that the version installed by other system is 3.x).</p></li>
<li><p>Fix <code>pexpect</code> by yourself.</p></li>
<li>Use some other python library.</li>
</ol>

<p>These avenues were all more or less hinted by github user @takluyver, apparently maintainer of <code>pexpect</code> in comment to issue #351:</p>

<blockquote>
  <p>@jquast any thoughts on what to do for this (and #356)? I feel bad that we've broken things people were doing with fdspawn, but I really don't want to make it inherit from the pty spawn class, and now that it works on Windows, I think it's important to preserve that too.</p>
  
  <p>Maybe we should just say:</p>
  
  <ul>
  <li>If you have legacy code that broke with Pexpect 4, downgrade to Pexpect 3.x (<code>pip install pexpect&lt;4</code>)</li>
  <li>If you're writing new code, use <a href="https://github.com/digidotcom/python-streamexpect" rel="nofollow">streamexpect</a> instead of pexpect.</li>
  </ul>
</blockquote>

python serial-port pexpect