explorerDude
explorerDude

Reputation: 323

python pty module - buffer hangs?

I am trying to make a small module which opens an ssh connection and allows to send commands over ssh and return the output of the command. Hereby, there should only be one ssh connection (so that multiple commands do not cause auto-blocks). I am aware of paramiko, but I cannot use it as I have to use python3.2 because of other constraints.

The module I wrote is here: http://kbicker.web.cern.ch/kbicker/ssh.py

In principle, it works. However, when using cat to read a text file, the program hangs. I determined that this is because reading a new line from the pty hangs. I assume, there is some kind of buffer problem, but I have no idea how to solve it.

I would also be grateful for any other advice on my code.

Thank you in advance for your help!

Upvotes: 1

Views: 569

Answers (2)

explorerDude
explorerDude

Reputation: 323

Solved, or at least worked around it:

By using a thread with the ssh -M option, I could have one Master ssh connection open and have commands open their own ssh subprocess, which connects through the master connection, thereby alleviating the need to open more than one connection.

Upvotes: 1

Guy
Guy

Reputation: 551

Try pexpect. I ran into a similar problem and it solved it.

Upvotes: 0

Related Questions