加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

Python,paramiko,invoke_shell和丑陋的字符

发布时间:2020-12-20 11:36:09 所属栏目:Python 来源:网络整理
导读:当我运行以下 Python代码时: import workflowimport consoleimport paramikoimport timestrComputer = 'server.com'strUser = 'user'strPwd = 'passwd'client = paramiko.SSHClient()client.set_missing_host_key_policy(paramiko.AutoAddPolicy())client.c
当我运行以下 Python代码时:

import workflow
import console
import paramiko
import time

strComputer = 'server.com'
strUser = 'user'
strPwd = 'passwd'

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname=strComputer,username=strUser,password=strPwd)

channel = client.invoke_shell()
channel.send('lsn')
time.sleep(3)
output=channel.recv(2024)
print(output)

#Close the connection
client.close()
print('Connection closed.')

我得到了与丑陋字符混合的所需输出:

Last login: Thu Jun 19 23:37:55 2014 from 192.168.0.10

ls
user@server:~$ls
[0m[01;34mbin[0m                                         Rplots1.pdf
[01;32mbtsync[0m                                      Rplots.pdf
btsync.conf~                                [01;31mrstudio-server-0.95.265-amd64.deb[0m
[01;31mbtsync_glibc23_x64.tar[0m                      screen.vba
[01;34mbudget[0m                                      [01;34mshiny[0m
[01;3
Connection closed.

任何人都可以解释我发生了什么,以及如何获得一个漂亮的输出?
谢谢

解决方法

这些是ls使用的终端颜色代码,用于突出显示目录,可执行文件等.您可以显式调用/ bin / ls(或者,在某些发行版上,ls –color = never)以避免调用别名等并获得无色输出.

颜色是使用像[0m [01; 34m.这是启用ls着色时终端的样子:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读