Python Forum

Full Version: pexpect log output
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi folks, this is my first post so apologies if this exists in a previous post. I'm using pexpect to automate network device configuration and I'd like to include instructions to log all activity to a file. Has anyone done this or have some advice where to start?

Cheers
From the help file:http://pexpect.readthedocs.io/en/stable/overview.html
Quote:It is also useful to log the child’s input and out to a file or the screen. The following will turn on logging and send output to stdout (the screen):
child = pexpect.spawn(foo)
child.logfile = sys.stdout
I haven't tested, but you should also be able to use something like:
child.logfile = open('mylogfilename, 'w')
Don't forget to close it before exiting the program
child.logfile.close()
Thank you :)