开发者

python pty module - buffer hangs?

开发者 https://www.devze.com 2023-04-12 13:17 出处:网络
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 mul

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 princi开发者_C百科ple, 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!


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号