当我使用python脚本远程连接输出时,输出未正确显示格式
我使用我的Python代码连接到远程服务器。 我连接并获得结果。但是结果是\ r \ n 我的代码在下面:
#To connect remote server and run networkmon.py and get results
from pexpect import pxssh
import getpass
try:
s = pxssh.pxssh()
hostname = "10.89.71.39"
username = "manoadmin"
password = "********" #generic pass added
s.login(hostname, username, password)
s.sendline('cat manobackup_scripts/networkmon.py')
s.prompt()
print(s.before)
s.logout()
except pxssh.ExceptionPxssh as e:
print("pxssh login hata.")
我得到的输出就像;
导入os \ r \ nimport套接字\ r \ n \ r \ r \ nimport time \ r \ n \ n \ r \ r \ nstart_time = time.time.time.time()\ r \ r \ n \ r \ r \ n
但我希望像下面一样打印出来
导入OS 导入套接字
导入时间
start_time = time.time()
I connect to remote server with ssh with my python codes.
I connect and get results. But results are coming with \r\n
My codes are below :
#To connect remote server and run networkmon.py and get results
from pexpect import pxssh
import getpass
try:
s = pxssh.pxssh()
hostname = "10.89.71.39"
username = "manoadmin"
password = "********" #generic pass added
s.login(hostname, username, password)
s.sendline('cat manobackup_scripts/networkmon.py')
s.prompt()
print(s.before)
s.logout()
except pxssh.ExceptionPxssh as e:
print("pxssh login hata.")
The output i get is like;
import os\r\nimport socket\r\n\r\nimport time\r\n\r\nstart_time = time.time()\r\n\r\n
But i want the out put to be printed out as below
import os
import socketimport time
start_time = time.time()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,
s.before
是bytes
,而不是str
。您可以在打印时解码:您可以要求它通过指定
编码
:By default data in
s.before
is ofbytes
, notstr
. You can decode when printing:You can ask it to automatically convert the data to
str
by specifying anencoding
: