Expect4j vs Pexpect: simple example


Staff member
I have Java code that uses <a href="https://code.google.com/p/expect4j/" rel="nofollow">Expect4j</a>. However, I need to rewrite this code into Python. And so I found <a href="https://pexpect.readthedocs.org/en/latest/" rel="nofollow">Pexpect</a>. Now, I am not really sure how to use any of these and were wondering if anybody could help me with that.

As I understand, the Java <a href="https://nikunjp.wordpress.com/2011/07/30/remote-ssh-using-jsch-with-expect4j/" rel="nofollow">version</a> usually begins like

channel = (ChannelShell) session.openChannel("shell")
Expect4j expect = new Expect4j(channel.getInputStream(), channel.getOutputStream());

How would this code look in Python? I have been looking for a few days now and am not really understanding it. I really haven't tried much because I feel like I'm stuck. For connecting to SSH I am going to use <a href="http://www.paramiko.org/" rel="nofollow">paramiko</a> (which I guess solves the very first line of code above)