我希望能够通过 SSH 连接控制远程 Python 解释器,并从 Python 本身驱动它。
我有一个基本模板:
ssh.connect(servername, serverport, username, key_filename=key_filename)
transport = ssh.get_transport()
channel = transport.open_session()
channel.exec_command(PATH_TO_EXEC)
while True:
r, w, e = select.select([channel], [], [], 1)
if channel in r:
try:
if channel.recv_ready():
x = channel.recv(64)
elif channel.recv_stderr_ready():
x = channel.recv_stderr(64)
else:
continue
if len(x) == 0:
print '\r\n*** EOF\r\n',
break
sys.stdout.write(x)
sys.stdout.flush()
except socket.timeout:
pass
pdb
这使我可以使用:与远程应用程序交谈channel.set("command\n")
。
bash
它与, with完美配合gdb
,但我无法从python
(v2)获取输出流
Python如何处理它的输出流,为什么我的代码不能用它?