网上看了一堆教程,全是错的,都是抄来抄去的答案
网上给的各种错误答案,比如这个(这个是错的):
process = pexpect.spawn("ftp sw-tftp", logfile=sys.stdout)
我tm怎么试都报错
在python3.7+pexpect4.6版本下,用此方法可以在linux控制台里输出信息
p = pexpect.spawn(cmd, encoding='utf-8')
p.logfile = sys.stdout
关键在于encoding和logfile的设定!
官方英文文档:https://pexpect.readthedocs.io/en/stable/api/pxssh.html?highlight=stdout