pexpect 日志 输出到文件
command = 'ssh -p' + str(port) + " " + username + '@' + host
child = pexpect.spawn(command)
fout = open('reboot.txt', 'ab') # 注意这里必须是追加,字节码模式
# child.logfile_read = sys.stdout
child.logfile = fout
pexpect 日志输出到标准输出
command = 'ssh -p' + str(port) + " " + username + '@' + host
#child = pexpect.spawn(command)
child = pexpect.spawn(command,encoding='utf-8') #这里必须添加字符编码
child.logfile_read = sys.stdout
本文介绍了如何使用pexpect模块将SSH命令的日志输出到文件中,并提供了两种不同的配置方式:一种是追加字节码模式,另一种是通过指定字符编码输出到标准输出。文章详细展示了如何设置pexpect.spawn对象的logfile属性来实现日志记录。
1185

被折叠的 条评论
为什么被折叠?



