增加 paramiko.SSHClient.exec_command() 宽度

increase paramiko.SSHClient.exec_command() width

我在远程服务器上使用 paramiko.SSHClient.exec_command() 到 运行 命令。 有人知道是否可以更改宽度,例如 invoke_shell(width=150) ?

当我 exec_command("ls -la") 我得到:

drwx------.  6 myuser myuser  4096 25 avril 15:59 
.
drwxr-xr-x. 14 root    root     4096  5 mai 15:05 
..
-rw-------.  1 myuser myuser  2818 28 avril 11:09 
.bash_history
-rw-r--r--.  1 myuser myuser   340 14 avril 14:16 
.bashrc

我想要:

drwx------.  6 myuser myuser  4096 25 avril 15:59 .
drwxr-xr-x. 14 root    root     4096  5 mai 15:05 ..
-rw-------.  1 myuser myuser  2818 28 avril 11:09 .bash_history
-rw-r--r--.  1 myuser myuser   340 14 avril 14:16 .bashrc

(使用 exec_command,而不是 invoke_shell)

我的代码:

ssh_client    = paramiko.SSHClient()
mykey         = paramiko.RSAKey.from_private_key_file("/path/to/my/key", password="passphrase")
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect("myserver.mydomain.com", username="myuser", pkey=mykey)
transport     = ssh_client.get_transport()
agent_channel = transport.open_session()
agent_handler = paramiko.agent.AgentRequestHandler(agent_channel)
stdin, stdout, stderr = ssh_client.exec_command("ls -la")

好的,找到了:这只是一个 pprint 奇怪的行为。我将接收到的行放在一个列表中,然后 pprint 这个列表。如果我这样做:

for line in received:
    print(line)

那就好了。 pprint 打印:

['-rw-r-----    1 myuser   mygroup      23228063744 06 mai 11:41 '
 'my_file.txt-rw-r-----    1 '
...

我不知道为什么。好吧,我将停止使用 pprint。