test.py 581 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. demeter core
  5. name:demeter.py
  6. author:rabin
  7. """
  8. import pexpect
  9. if __name__ == '__main__':
  10. user = 'root'
  11. ip = '192.168.33.10'
  12. port = '3309'
  13. password = '123456'
  14. child = pexpect.spawn('mysql -u%s -h%s -P%s -p' % (user, ip, port))
  15. child.expect ('password:')
  16. child.sendline (password)
  17. child.expect('>')
  18. child.sendline('show databases;')
  19. #print child.before # Print the result of the ls command.
  20. child.sendline('exit')
  21. child.interact() # Give control of the child to the user.