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