Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.9k views
in Technique[技术] by (71.8m points)

python - Output of command executed with Paramiko invoke_shell() is paginated (getting "--more--" in recv)

I have a command XYZ sent over a channel using the sendall()

channel = ssh.invoke_shell()
channel.sendall('XYZ
')
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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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):

If the above does not help with removing the --more--, and you are connecting to a Cisco device, sending the following command to the device may help:

terminal length 0

See also How to proceed with the word "MORE" to get to the end of the command.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...