# python subprocess模塊使用例子 import subprocess mysql_login = ["mysql", "-h", "localhost", "-u", "root", "-p", "1234"] mysql_cmd = mysql_login + ["-e", "show databases;use mysql;show tables;"] p = subprocess.Popen(mysql_cmd, stdout=subprcess.Pipe, stderr=subprcess.Pipe, ) stdout, stderr = p.communicate() #怕輸出太多,使用內存 print stdout