问题
I have a command XYZ
sent over a channel using the sendall()
channel = ssh.invoke_shell()
channel.sendall('XYZ\n')
response = channel.recv(2000)
I should have the entire output right there, but then I notice that in the last line of the output that I do receive, there is a "--more--" at the end. Like the one that you get when you use the 'less' command.
As a result, the channel is still waiting for more output because the buffer is not empty (more output is expected) and the command is expecting me to press SPACE to display more of the output.
The channel just waits forever.
How do I get the entire output in one go? I do not want that "--more--".
Increasing the buffer size makes no difference.
回答1:
Use the exec_command, not the invoke_shell
+ sendall
.
The invoke_shell
(with default arguments) emulates an interactive 80x24 terminal. What makes the command you are executing do fancy stuff like pagination.
def invoke_shell(self, term='vt100', width=80, height=24, width_pixels=0,
height_pixels=0):
While the exec_command
(with default arguments, namely the get_pty=False
) uses a non-interactive terminal. What should make the command (if implemented properly) avoid doing pagination.
def exec_command(self, command, bufsize=-1, timeout=None, get_pty=False):
来源:https://stackoverflow.com/questions/31999373/output-of-command-executed-with-paramiko-invoke-shell-is-paginated-getting